Yes - "some input" is not a valid base64 encoded string.
The idea of base64 is that you encode binary data into text. Then you decode this text data into an array of bytes. You cannot simply decode any arbitrary text, as if it were a complete base64 message, moreover, you can try to decode mp3 as a jpeg image.
String encryption should be as follows:
- Encode a string to binary data, for example. using UTF-8 (
text.getBytes("UTF-8") ) - Encrypt binary data with AES
- Encode cyphertext with Base64 to get text
Decryption is a question:
- Decode base64 text to binary cyphertext
- Decrypt cyphertext to get binary plaintext
- Decoding binary plaintext to a string using the same encoding as the first step above, for example.
new String(bytes, "UTF-8")
source share