Deriving ECDSA Public Key from Private Key

前端 未结 3 1697
既然无缘
既然无缘 2021-01-03 01:41

I was attempting to generate a public ECDSA key from a private key, and I haven\'t managed to find much help on the internet as to how to do this. Pretty much everything is

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 01:53

    So after a while, I figured out a solution and decided to post it in case anyone else has the same issue as me:

    KeyFactory keyFactory = KeyFactory.getInstance("ECDSA", "BC");
        ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp256k1");
    
        ECPoint Q = ecSpec.getG().multiply(((org.bouncycastle.jce.interfaces.ECPrivateKey) this.privateKey).getD());
    
        ECPublicKeySpec pubSpec = new ECPublicKeySpec(Q, ecSpec);
        PublicKey publicKeyGenerated = keyFactory.generatePublic(pubSpec);
        this.publicKey = publicKeyGenerated;
    

    EDIT: Removed the code decoding the ECPoint as per @MaartenBodewes comment.

提交回复
热议问题