During development of the project in which it is necessary to encrypt the data read from the XML file, and then write to another file and decrypt it. The problem is that when reading the encrypted file, XML service symbols appear which are not read and give an error. The question is how do I read data from a file?
Encryption Algorithms
Listing of code where I read file
try {
File file = new File(filePath);
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory
.newInstance();
DocumentBuilder documentBuilder =
documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(file);
password =
document.getElementsByTagName("KeyWord").item(0).getTextContent();
encDataAES =
document.getElementsByTagName("AES").item(0).getTextContent();
encDataRSA =
document.getElementsByTagName("RSA").item(0).getTextContent();
} catch (Exception e) {
System.out.println("Error reading configuration file:");
System.out.println(e.getMessage());
}
Asked
Active
Viewed 71 times
0

Alex Weiss
- 21
- 1
- 4
-
first of all if your XML is encoded by XML escape, you need to unescape it using Apache StringEscapeUtils. to handle this error, you have to play with string escape characters a bit. – A.Shaheri Nov 04 '17 at 13:44
-
Consider using standard XMLenc which avoids this problem by [base64 encoding the ciphertext](https://www.w3.org/TR/2002/REC-xmlenc-core-20021210/Overview.html#sec-CipherData) – dave_thompson_085 Nov 04 '17 at 18:56