JAVA: 128-bit key to String problem and back
I have created a SecretkeySpec object wich contains a 128 bit key. I would like to have this key in a String(this string needs to be put back in to the original key later), so i use Base64 encoding.
This is how my key looks in raw format from the byte array into chars:
So I take the bytes and encode it like this.
byte okay = Base64.encode(eF.getSpec().getEncoded());
Now when i translate it into chars i get:
Now i want to have my key back restored to it's original format from the base64 encoded array.
String dkey = "S2xEa3Ara0o5blVGYTB3WkRIeUZmZz09DQo="; byte key = null; key = dKey.getBytes(); key = Base64.decode(key);
Now when i check the result i get:
As you can see this is not the result i hoped to see. I surely made a novice mistake, and forgive me for that but i am relativaly new to programming. I would appreciate it if someone could give me a working example of transforming the 128 bit key to and from readable format, and perhaps an explanation where i went wrong with thinking.
And i apologize for any spelling mistakes, English is not my native language.
Thanks in advance
Is the extra D at the beginning a copy and paste error?
in turn is a valid base64 string that decodes to some binary data. So it seems that you are doing the encoding twice.
Now when i translate it into chars i get
How exactly are you doing that? Is there another base64 encoding involved in that step?