我正在使用bouncycastle(JAVA)在簽名,加密,解密和簽名的驗證中實現SSO。 我有原始的PGP公鑰和私鑰,我需要將它們存儲在Java密鑰庫中。 這些PGP公鑰沒有證書。在java keystore中存儲PGP(public)鍵 - Bouncycastle
據我所知,對於公鑰(根據Keystore的javadoc:http://docs.oracle.com/javase/6/docs/api/java/security/KeyStore.html)我必須創建證書。創建證書後,我可以將其作爲KeyStore.TrustedCertificateEntry導入密鑰庫。 但是,我無法爲類型org.bouncycastle.openpgp.PGPPublicKey創建證書條目。
我已經通過網絡搜索,但沒有找到任何有效的例子:
- BouncyCastle的文檔:http://www.bouncycastle.org/wiki/display/JA1/X.509+Public+Key+Certificate+and+Certification+Request+Generation 生成X.509證書密鑰 -
BouncyCastle的例子 - org.bouncycastle.openpgp。 examples.DirectKeySignature: 將certificat(類型爲PGPSignature的對象)直接添加到PGPPublicKey。 總結 - 我已簽署(認證)PGPPublicKey,但我無法將此類型的密鑰存儲到Java密鑰庫中。
OutputStream out = new ByteArrayOutputStream(); if (armor) { out = new ArmoredOutputStream(out); } PGPPrivateKey pgpPrivKey = secretKey.extractPrivateKey(secretKeyPass.toCharArray(), "BC"); PGPSignatureGenerator sGen = new PGPSignatureGenerator(secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1, "BC"); sGen.initSign(PGPSignature.DIRECT_KEY, pgpPrivKey); BCPGOutputStream bOut = new BCPGOutputStream(out); sGen.generateOnePassVersion(false).encode(bOut); PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); boolean isHumanReadable = true; spGen.setNotationData(true, isHumanReadable, notationName, notationValue); PGPSignatureSubpacketVector packetVector = spGen.generate(); sGen.setHashedSubpackets(packetVector); bOut.flush(); return PGPPublicKey.addCertification(keyToBeSigned, sGen.generate()).getEncoded();
我感興趣的主要是程序上的解決方案(Java源代碼),但使用一些工具將有助於太例子。
謝謝!