views:

122

answers:

1

hi everyone,

i would like to know how to convert byte array into key.

i am doing an AES encryption/decryption. instead of generating a key, i would like to use my generated byte array.

byte[] clientCK = Milenage.f3(sharedSecret16, RANDbytes, opc);  

let say i have a byte array called clientCK, stated above. i want to use it in AES encryption as shown below.

Cipher c = Cipher.getInstance("AES");
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encValue = c.doFinal(valueToEnc.getBytes());
String encryptedValue = new BASE64Encoder().encode(encValue);

therefore, i need to convert that byte array clientCK into key format. please help.

+1  A: 

You may want to use a SecretKeySpec:

public SecretKeySpec(byte[] key, String algorithm)

Constructs a secret key from the given byte array.

polygenelubricants