[英]Java: Get Key from encoded key
How to get back from encoded byte[] to java.security.Key? 如何从编码的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[]?
}
}
Found! 找到了! http://www.exampledepot.com/egs/javax.crypto/GetKeyBytes.html
http://www.exampledepot.com/egs/javax.crypto/GetKeyBytes.html
Sorry for the inconvenience. 抱歉给你带来不便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.