我需要使用C#将AES 256位密钥存储在密钥库中。我尝试使用Org.BouncyCastle.Pkcs.Pkcs12Store,但无法存储AES密钥。我可以使用以下代码在JAVA中完成此操作,但在C#中无法做到这一点。
try{
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(null, null);
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(256);
Key key = keyGen.generateKey();
for(byte b: key.getEncoded()) {
System.out.print(b);
}
System.out.println("");
keyStore.setKeyEntry("secret", key, "password".toCharArray(), null);
keyStore.store(new FileOutputStream("output.p12"), "password".toCharArray());
try{
keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(new FileInputStream("output.p12"), "password".toCharArray());
Key pvtKey = keyStore.getKey("secret", "password".toCharArray());
//System.out.println(pvtKey.getEncoded().toString());
for(byte b: pvtKey.getEncoded()) {
System.out.print(b);
}
System.out.println("");
} catch (Exception ex){
ex.printStackTrace();
}
} catch (Exception ex){
ex.printStackTrace();
}
请帮帮我。