如何从 AsymmetricCipherKeyPair 创建 PGP Public 和私钥?
How to create PGP Public and Private keys from AsymmetricCipherKeyPair?
我的目标是生成 armoer 椭圆曲线 (ECC) public 和私钥。所以我已经实现了 AsymmetricCipherKeyPair,现在我必须将它转换为 OpenPGP 密钥,以便将它传递给 KeyRingGenrator。
X9ECParameters parms = ECNamedCurveTable.getByOID(new ASN1ObjectIdentifier("curve25519"));
ECParameterSpec domainparams = EC5Util.convertToSpec(parms);
ECDomainParameters domainParams = EC5Util.getDomainParameters(null,domainparams);
SecureRandom secureRandom = new SecureRandom();
ECKeyGenerationParameters keyParams = new ECKeyGenerationParameters(domainParams, secureRandom);
ECKeyPairGenerator generator = new ECKeyPairGenerator();
generator.init(keyParams);
AsymmetricCipherKeyPair keyPair = generator.generateKeyPair();
密钥对生成后,我必须将其转换为OpenPGP密钥对,以便在下面的函数中传递。
PGPKeyPair eccKeyPair = new PGPKeyPair("openPGPPublicKey", "openPGPPrivateKey");
此函数进一步用于密钥环生成。
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator (PGPSignature.DEFAULT_CERTIFICATION,
eccKeyPair ,
"umaimaahmed1@gmail.com", null, null,
null, new BcPGPContentSignerBuilder(PGPPublicKey.EC,
HashAlgorithmTags.SHA256),
new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));
在查看 API 文档时,我发现:
Deprecated. use BcPGPKeyPair
or JcaPGPKeyPair
as appropriate.
BcPGPKeyPair
呢?
毕竟,您正在使用 Bouncy Castle 的轻量级 API 生成密钥对。
我的目标是生成 armoer 椭圆曲线 (ECC) public 和私钥。所以我已经实现了 AsymmetricCipherKeyPair,现在我必须将它转换为 OpenPGP 密钥,以便将它传递给 KeyRingGenrator。
X9ECParameters parms = ECNamedCurveTable.getByOID(new ASN1ObjectIdentifier("curve25519"));
ECParameterSpec domainparams = EC5Util.convertToSpec(parms);
ECDomainParameters domainParams = EC5Util.getDomainParameters(null,domainparams);
SecureRandom secureRandom = new SecureRandom();
ECKeyGenerationParameters keyParams = new ECKeyGenerationParameters(domainParams, secureRandom);
ECKeyPairGenerator generator = new ECKeyPairGenerator();
generator.init(keyParams);
AsymmetricCipherKeyPair keyPair = generator.generateKeyPair();
密钥对生成后,我必须将其转换为OpenPGP密钥对,以便在下面的函数中传递。
PGPKeyPair eccKeyPair = new PGPKeyPair("openPGPPublicKey", "openPGPPrivateKey");
此函数进一步用于密钥环生成。
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator (PGPSignature.DEFAULT_CERTIFICATION,
eccKeyPair ,
"umaimaahmed1@gmail.com", null, null,
null, new BcPGPContentSignerBuilder(PGPPublicKey.EC,
HashAlgorithmTags.SHA256),
new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));
在查看 API 文档时,我发现:
Deprecated. use
BcPGPKeyPair
orJcaPGPKeyPair
as appropriate.
BcPGPKeyPair
呢?
毕竟,您正在使用 Bouncy Castle 的轻量级 API 生成密钥对。