1

My goal is to create Elliptical curve key pairs from it using spongy castle library and then armor it.

      X9ECParameters curve = ECNamedCurveTable.getByName("secp256k1");
        ECDomainParameters domainParams = new ECDomainParameters(curve.getCurve(),curve.getG(), curve.getN(), curve.getN(), curve.getSeed());

        SecureRandom secureRandom = new SecureRandom();
        ECKeyGenerationParameters keyParams = new ECKeyGenerationParameters(domainParams, secureRandom);

        ECKeyPairGenerator generator = new ECKeyPairGenerator();
        generator.init(keyParams);
        AsymmetricCipherKeyPair kp= generator.generateKeyPair();

char[] passPhrase = "hello".toCharArray();
        PGPKeyPair ecKeyPair = new BcPGPKeyPair(PGPPublicKey.ECDH, kp, new Date());

PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator
                (PGPSignature.DEFAULT_CERTIFICATION,
                        ecKeyPair,
                        "umaimaahmed1@gmail.com", null, null,
                        null, new BcPGPContentSignerBuilder(PGPPublicKey.EC,
                        HashAlgorithmTags.SHA256),
                        new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));

After this the parsed armored key ring generation is executed.

It works fine for RSA but for ECC implementation I get an exception of illegal object in getInstance: org.spongycastle.asn1.x9.X962Parameters

when it hits the linePGPKeyPair ecKeyPair = new BcPGPKeyPair(PGPPublicKey.ECDH, kp, new Date());

I cant find anything on the internet to generate PGP Key Rings from ECC key pairs.

  • I see two issues with your code after reading it for the first time, maybe you can check if you can change them in your code. First of all, you specify explicit parameters, which you convert from the *named curve*. It is however likely that PGP expects a named curve rather than an explicit set of parameters. Second, you use `PGPPublicKey.ECDH`. That's certainly incorrect, the PGP key is a signing they and is therefore using `ECDSA`, so use that if it is available. – Maarten Bodewes Jul 01 '19 at 21:42
  • @MaartenBodewes I have changed PGPPublicKey.EC to PGPPublicKey.ECDSA, but I didn't get your first statement. I want to use Elliptical curve "curve25519" so for that I would be using `X9ECParameters parms = CustomNamedCurves.getByName("curve25519");` but still no luck. Can you kindly let me know how to resolve this? – Umaima Khurshid Ahmad Jul 02 '19 at 07:58

0 Answers0