This is the hex format of a secret key used for AES encryption
00010203050607080A0B0C0D0F101112
Can i generate the original SecretKey format or byte array from this?
If so how?
This is the hex format of a secret key used for AES encryption
00010203050607080A0B0C0D0F101112
Can i generate the original SecretKey format or byte array from this?
If so how?
A SecretKey
is an interface. What type was the implementation? J2SE has two implementing classes, KerberosKey
and SecretKeySpec
, both which have constructors with a byte array as a parameter.
What is the original SecretKey format?
Are you aware byte[]
contains signed bytes valued from -128 to 127?
Would it hurt if you tried this:
byte[] key = {
0x00,0x01,0x02,0x03,0x05,0x06,0x07,0x08,
0x0A,0x0B,0x0C,0x0D,0x0F,0x10,0x11,0x12
};
Note: If you have values like 0x80 - 0xFF you'll need to cast them as (byte)0x80 - (byte)0xFF to avoid a warning about the range.
You can use Apache Commons Codec to perform the hex decoding,
If you don't want use any libraries, you can also do this,
byte[] bytes = new BigInteger("7F" + str, 16).toByteArray();
SecretKeySpec key = new SecretKeySpec(bytes, 1, bytes.length-1, "AES");
You have to add an extra byte 0x7F to prevent BigInteger from stripping leading zeros or adding signed bytes.