views:

81

answers:

1

How to get back from encoded byte[] to java.security.Key?

import java.security.Key;
import javax.crypto.SecretKey;
import javax.crypto.KeyGenerator;

public class TestRSA {

    public static void main(String[] args) throws Exception {

    KeyGenerator kgen = KeyGenerator.getInstance("AES");
    kgen.init(128);
    SecretKey key = kgen.generateKey();
    byte[] encoded = key.getEncoded();

    // now, how to get back the Key object from the encoded byte[]?

    }
}
A: 

Found! http://www.exampledepot.com/egs/javax.crypto/GetKeyBytes.html

Sorry for the inconvenience.

Tom Brito