Skip to content
Advertisement

Convert AWS KMS ECDSA_SHA_256 Signature from DER encoded ANS.1 format to JWT base64url encoded R || S format in NodeJS/Javascript

I am trying to create JWT Signature in NodeJS with ES256 algorithm using AWS KMS Customer Managed Keys.

The signature created using AWS KMS with cryptographic Signing Algorithms ECDSA_SHA_256 is not JWT accepted R || S format. As per AWS doc, Signature will be in DER encoded ANS X9.62–2005 format (https://docs.aws.amazon.com/kms/latest/APIReference/API_Sign.html#API_Sign_ResponseSyntax).

I tried to convert the AWS KMS Sign to JWT R||S format using below code in NodeJS with ans1js(https://www.npmjs.com/package/asn1js), But the R and S length is not consistent to be 32 + 32 rather it varies 33 most of the time.

JavaScript

Complete Code for Signature creation:

JavaScript

Any NodeJs Javascript implementation to convert the DER encoded ANS format to R || S format base64url encoded?

Advertisement

Answer

Any NodeJs Javascript implementation to convert the DER encoded ANS format to R || S format base64url encoded?

Yes, ecdsa-sig-formatter will help you convert signatures back and forth between the formats.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement