Thank you so much for your reply. Just I happened to see your reply today. I gone thorugh the code and I have created the sample program as well. is the any way we can avoid special characters in the encoded output? is there any way the output can only be restricted to data type specific?
Your help would be really appreciated and it will help me a lot.
Just to be precise: the data is *encrypted*, not *encoded*. As such it is binary, not text - so it doesn't have any "characters" in it, and can't be treated as text (or stored as a String). If you need to treat it as text, then you need to encode the ciphertext using something like base-64 encoding.
Here is my sample java code and output as below. In the encrypted output I should not have any special character. It should have only alphanumeric. And another thing is possible to get output length as specified by us? Thank you for your help
Before Encryption : Testing encryption
After Encryption : 5Mpp1Vwej3jfnyck99F0u0UaqxUkNH4ky3Z9BbxlvUA=
After Decryption : Testing encryption
Balasubramaniam Muthusamy wrote:Here is my sample java code and output as below. In the encrypted output I should not have any special character. It should have only alphanumeric.
When you use Base64 encoding, as you are doing, you will not get only alphanumeric characters (i.e. characters in the ranges A-Z, a-z and 0-9); you might also get characters like '='. If you don't want that, then use some other encoding algorithm instead of Base64, that only produces alphanumeric characters.
Note also that catching exceptions and doing nothing with them, as you do in lines 59 - 60, is a bad idea. If an exception happens, you'll never know.
Also, it's not a good idea to use internal Sun classes, such as sun.misc.BASE64Encoder and sun.misc.BASE64Decoder. These classes are not part of Java's public API and they might not exist on all JVM implementations, or they might not even exist in a future version of Oracle's JVM implementation. If you do need to use Base64 encoding, then use a third-party library with a supported API instead, for example Apache Commons Codec.