jwk-thumbprint
![CircleCI](https://circleci.com/gh/nwtgck/jwk-thumbprint-npm.svg?style=shield)
JWK Thumbprint for JavaScript/TypeScript on both Web Browser and Node.js
Installation
npm i -S jwk-thumbprint
Usage
Here is an usage to reproduce the example in RFC7638 3.1.
import {jwkThumbprint} from 'jwk-thumbprint';
const myJwk: JsonWebKey & {kty: 'RSA', kid: string} = {
kty: 'RSA',
n: '0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw',
e: 'AQAB',
alg: 'RS256',
kid: '2011-04-29',
};
console.log(jwkThumbprint(myJwk, 'SHA-256'));
Thumbprints in number array, hex and base64url encodings
First, import the following.
import {jwkThumbprintByEncoding} from 'jwk-thumbprint';
You can get different encodings by 'number'
, 'hex'
, 'base64url'
or 'uint8array'
in type-safe way. The return types are properly typed by the encodings.
const thumbprint: number[] = jwkThumbprintByEncoding(jwk, "SHA-256", 'numbers');
console.log(thumbprint)
const thumbprint: string = jwkThumbprintByEncoding(jwk, "SHA-256", 'hex');
console.log(thumbprint)
const thumbprint: string = jwkThumbprintByEncoding(jwk, "SHA-256", 'base64url');
console.log(thumbprint)
const thumbprint: Uint8Array = jwkThumbprintByEncoding(jwk, "SHA-256", 'uint8array');
console.log(thumbprint)