我嘗試生成RSA密鑰對並將其存儲在HSM密鑰庫中。該代碼,我現在看起來是這樣的:RSA密鑰對生成並存儲到密鑰庫
String configName = "C:\\eTokenConfig.cfg";
Provider p = new sun.security.pkcs11.SunPKCS11(configName);
Security.addProvider(p);
// Read the keystore form the smart card
char[] pin = { 'p', '4', 's', 's', 'w', '0', 'r', 'd' };
KeyStore keyStore = KeyStore.getInstance("PKCS11",p);
keyStore.load(null, pin);
//generate keys
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA",p);
kpg.initialize(512);
KeyPair pair = kpg.generateKeyPair();
PrivateKey privateKey = pair.getPrivate();
PublicKey publicKey = pair.getPublic();
// Save Keys How ???
我試圖用keyStore.setEntry方法,但問題是,它需要一個證書鏈,我不知道如何得到這個證書?
不幸的是,當私鑰從PKCS#11設備「不可提取」時,此解決方案不起作用。 'privateKey.getEncoded()'可能返回'null' – Jcs 2014-05-02 16:59:44