Hi,
I have a string literal representation of a HEX value key which I use to send encrypted data from C++ to Java (on Sockets).
I haven't managed to convert the string representation to a value that I can use with SecretKeySpec() constructor to create a working AES 128b key.
The last attempt was this:
String strKey = new String("E5E6E7E9EA392A2B2D256489012145E5");
byte[] byteKey = new BigInteger(strKey,16).toByteArray();
SecretKey skey = new SecretKeySpec(byteKey, "AES");
It didn't work because the byte array was of size 17 byte. (java.security.InvalidKeyException: Invalid AES key length: 17 bytes)
Is there an obvious straight forward way to this which I'm missing? (How would you transfer a key in HEX representation?)
Thank you.