6

I am having problems using a public EC key in JWK format in Objective C with CommonCrypto.

I have a java example of what I can't seem to do in Objective C. This is pulled from the Nimbus Jose JWT library at https://static.javadoc.io/com.nimbusds/nimbus-jose-jwt/2.24/src-html/com/nimbusds/jose/jwk/ECKey.Curve.html

public ECPublicKey toECPublicKey() throws NoSuchAlgorithmException, InvalidKeySpecException {

    ECParameterSpec spec = crv.toECParameterSpec();

    if (spec == null) {
        throw new NoSuchAlgorithmException("Couldn't get EC parameter spec for curve " + crv);
    }

    ECPoint w = new ECPoint(x.decodeToBigInteger(), y.decodeToBigInteger());
    ECPublicKeySpec publicKeySpec = new ECPublicKeySpec(w, spec);
    KeyFactory keyFactory = getECKeyFactory();
    return (ECPublicKey)keyFactory.generatePublic(publicKeySpec);
}

I cannot find how to accomplish this in Objective C as CommonCrypto seems to lack JWK support. Does anyone have an idea on how I can get the other party's JWK key into a readable format (.pem, SecKeyRef, or NSData) from the x and y values of the curve?

0 Answers0