When I am using (encrypt/decrypt) javax.crypto.Cipher class for long string, some characters in output string are invalid.
//ecnryption
byte[] inputBytes = str.getBytes();
cypheredBytes = cipher.doFinal(inputString, 0, inputBytes, outputBytes, 0);
return new String(outputBytes, 0, cypheredBytes);
//decryption
byte[] inputBytes = str.getBytes();
cypheredBytes = cipher.doFinal (inputBytes, 0, inputBytes.length, outputBytes, 0);
return new String(outputBytes, 0, cypheredBytes);
I guess it’s a problem with character encodings.
The following transformation may be not reversible:
Keep the encrypted message as a
byte[]instead ofString.Also, the following lines depend on system default encoding:
Consider explicit encoding specification: