node-jose icon indicating copy to clipboard operation
node-jose copied to clipboard

Can this package convert a Uint8Array to JWK object

Open abhijithvijayan opened this issue 6 years ago • 1 comments

Is it possible for a Uint8Array to be set with the structure of a JWK object using this library in browser

Input:

Uint8Array(32) [16, 242, 193, 235, 85, 252, 66, 94, 118, 129, 203, 86, 48, 212, 115, 194, 174, 233, 55, 141, 48, 208, 236, 48, 85, 16, 161, 166, 145, 172, 53, 82]

produce output like:

KCVXrFs8oJBheco-JxbHkPL9bxyN5\WZ68hyfVgrBuJg

The whole expected output is something like

{ 
”alg”:”A256GCM”,
”ext”:false,
”k”:”KCVXrFs8oJBheco-JxbHkPL9bxyN5\WZ68hyfVgrBuJg”,
”key_ops”:[”encrypt”,”decrypt”],
”kty”:”oct”,
”kid”:”mp”
}

All the fields are not necessary.

abhijithvijayan avatar Jun 22 '19 12:06 abhijithvijayan

Edit:

Does this have something to do with

key being

Uint8Array(32) [34, 65, 121, 36, 183, 197, 183, 130, 34, 190, 4, 195, 24, 222, 144, 19, 53, 190, 13, 22, 227, 86, 57, 198, 43, 88, 82, 76, 160, 40, 110, 213]

const base64uriString = jose.util.base64url.encode(jose.util.asBuffer(key));
console.log('base64url : ', base64uriString);

producing output

base64url :  IkF5JLfFt4IivgTDGN6QEzW-DRbjVjnGK1hSTKAobtU

abhijithvijayan avatar Jun 22 '19 13:06 abhijithvijayan