Generating the ECDSA public key on the host side from the W parameter

I want to send the public key of a private-public key pair (ECDSA) generated in my applet to the host application / terminal.

In RSA, I used to send a modulus and a metric and generate a public key on the host side.

In ECDSA, I read from the link that we can do the same if you take the bytes of the W parameter outside of the map stackoverflow

Now I have W bytes. can anyone suggest how to generate a public key from this?

+3


source to share


1 answer


I wrote this method to convert an EC public key to a java.security.interfaces.ECPublicKey

key object . For this I am using the Bouncy Castle ( bcprov-ext-jdk16-1.46.jar

) provider . You can download the latest version here .



/**
 * This method converts the EC public key (ECPublicKey#getW()) into ECPublicKey
 * @param cardPublicKey as W
 * @param curveName (for example "P-224")
 * @return java.security.interfaces.ECPublicKey
 */
public ECPublicKey ucPublicKeyToPublicKey(byte[] cardPublicKey, String curveName) {
    //for example curveName = "P-224";
    java.security.interfaces.ECPublicKey ecPublicKey = null; // java.security.interfaces.ECPublicKey
    java.security.KeyFactory kf = null;

    org.bouncycastle.jce.spec.ECNamedCurveParameterSpec ecNamedCurveParameterSpec = ECNamedCurveTable.getParameterSpec(curveName);
    org.bouncycastle.math.ec.ECCurve curve = ecNamedCurveParameterSpec.getCurve();
    java.security.spec.EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, ecNamedCurveParameterSpec.getSeed());
    java.security.spec.ECPoint ecPoint = ECPointUtil.decodePoint(ellipticCurve, cardPublicKey);
    java.security.spec.ECParameterSpec ecParameterSpec = EC5Util.convertSpec(ellipticCurve, ecNamedCurveParameterSpec);
    java.security.spec.ECPublicKeySpec publicKeySpec = new java.security.spec.ECPublicKeySpec(ecPoint, ecParameterSpec);

    try {
        kf = java.security.KeyFactory.getInstance("EC", "BC");
    } catch (Exception e) {
        System.out.println("Caught Exception kf : " + e.toString());
    }

    try {
        ecPublicKey = (ECPublicKey) kf.generatePublic(publicKeySpec);
    } catch (Exception e) {
        System.out.println("Caught Exception public key: " + e.toString());
    }

    return ecPublicKey;
}

      

+2


source







All Articles