I import an XML file as a byte array to the project
RandomAccessFile rnd = new RandomAccessFile(filePath, "r");
byte[] fileData = new byte[(int) rnd.length()];
rnd.read(fileData);
I encrypted the array using java.crypto
Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
byte[] encypted = new byte[cipher.getOutputSize(fileData.length)];
int len = cipher.update(fileData, 0, fileData.length, encypted, 0);
len += cipher.doFinal(encypted, len);
When I decrypt the byte array and print it using
System.out.println(new String(decrypted, "UTF-8"));
I got the XML file but there were some unkown characters at the end (they are only at the end). Is there any way I can remove this?
Thanks in advance
see a similar question here, the answer though is what might be very relavent to your situation:
and incase this is relavant to you here is a link on padding patterns etc: Padding Wikipedia
This over here is also a very good tutorial for encrypting using DES: http://www.exampledepot.com/egs/javax.crypto/desstring.html and here is for PBE in DES:
PBE with HMAC(SHA1) and DES(EDE)