Java:从编码密钥获取密钥

时间:2010-04-06 19:56:06

标签: java security encryption encoding

如何从编码的byte []返回到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[]?

    }
}

1 个答案:

答案 0 :(得分:0)

实测值! http://www.exampledepot.com/egs/javax.crypto/GetKeyBytes.html

很抱歉给您带来不便。