Using Ethereum compressed public key to create JWE
How do I setup an encrypter when starting with an Ethereum compressed public key string, like ‘0x032be803b18b3ce72d9760c8f736cb08cf3eb42c5ed2d907616afca15a2e3fb4c0’?
I’m attempting to encrypt a JWT into a JWE, and I think it needs to be a ECDHEntrypter.
Comments (4)
-
-
reporter For anyone else with this issue, I think I have it working now. When creating the JWK, the x parameter is the compressed public key minus the left 4 characters (0x03 in the example above).
// Create encrypter var jwk = '{"kty":"OKP","crv":"X25519","x":"#local.x#","use":"enc","kid":"1"}' var jwk2 = createObject("java", "com.nimbusds.jose.jwk.OctetKeyPair").parse(jwk); var encrypter = createObject("java", "com.nimbusds.jose.crypto.X25519Encrypter").init(jwk2); // Create header & payload var jweHeader = createObject("java", "com.nimbusds.jose.JWEHeader").parse('{"alg":"ECDH-ES","enc":"XC20P","cty":"JWT"}'); var payload2 = createObject("java", "com.nimbusds.jose.Payload").init(arguments.payload); // Creates the JWE object with payload jweObject = createObject("java", "com.nimbusds.jose.JWEObject").init(jweHeader,payload2); // Encrypt the JWT jweObject.encrypt(encrypter); // Serialize the JWE to compact form jwe = jweObject.serialize();
-
When you write compressed, is this truly compressed (e.g. ZIP), or simply hex encoded?
-
reporter An uncompressed Ethereum public key contains both the x and y axis coordinates of the point on the curve. The compressed key contains just the x axis and an indicator for whether the y axis is positive or negative. Both are hex encoded. More info at https://medium.com/asecuritysite-when-bob-met-alice/02-03-or-04-so-what-are-compressed-and-uncompressed-public-keys-6abcb57efeb6
- Log in to comment
This depends on the key type / curve and what the compression algorithm is.