I have java application that sending(HTTP post method) credit card numbers to the supplier via the XML.
When writing the XML file, currently credit card number also printing in the file. But it is not good practice to write the credit card numbers directly in to the file without encrypting.
I do not want to encrypt the entire XML, because we are sending the secure information through HTTPS link and hence I assume it provide necessary security. So I want to encrypt only the credit card number element while writing to the file in the Java environment.
String xmlRequest = <?xml version='1.0'?>
<ReservationRequest>
<Passenger>
<firstName>XXX</firstName>
<lastName>YYY</lastName>
</Passenger>
<CreditCard Currency='USD'>
<Number>1234567812345678</Number>
<cvv>123</cvv>
<Expiration>12/12</Expiration>
</CreditCard>
</ReservationRequest>
Please note that I want to write to file the same string that send to the supplier.
Here check whether card number is blank or empty. If we get the card number, then only mask the string content while writing to the file.
Output