java - Why i need to use Base64 in this encryption -
i see encryption in java.in generate secret key have
keygenerator keygen = keygenerator.getinstance("des"); key secretkey = keygen.generatekey(); byte[] keybytes = secretkey.getencoded() key secretkey = keygen.generatekey(); byte[] key = secretkey.getencoded(); byte[] encodedkey=base64.encodebase64(key ); string keytext = new string(encodedkey);
my question why need of using base64.encodebase64(key)
. problem if use directly
string keytext = new string(key);
i confusing.please me.thanks in advance...
not every sequence of bytes represents valid string
: you need know character encoding in order interpret sequence of bytes string. since java's char
16-bit, random sequence of bytes can end representing string invalid code points in it. using base-64 encoding fixes problem ensuring elements valid characters [a-za-z0-9+/]
range.
Comments
Post a Comment