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:
*P??? ?ukL|?~
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:
S2xEa3Ara0o5blVGYTB3WkRIeUZmZz09DQo=
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:
DKlDkp+kJ9nUFa0wZHyFfg==
instead of:
*P??? ?ukL|?~
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
decodes to
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.
How exactly are you doing that? Is there another base64 encoding involved in that step?