【问题标题】:How to create PGP Public and Private keys from AsymmetricCipherKeyPair?如何从 AsymmetricCipherKeyPair 创建 PGP 公钥和私钥?
【发布时间】:2019-07-02 12:02:40
【问题描述】:

我的目标是生成 armoer 椭圆曲线 (ECC) 公钥和私钥。所以我已经实现了 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));

【问题讨论】:

    标签: java android cryptography openpgp


    【解决方案1】:

    查看 API 文档时,我发现:

    已弃用。酌情使用BcPGPKeyPairJcaPGPKeyPair

    BcPGPKeyPair 呢?

    毕竟,您是在使用 Bouncy Castle 的轻量级 API 生成密钥对。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 2019-02-28
      • 2017-11-12
      • 2021-12-16
      • 1970-01-01
      相关资源
      最近更新 更多