Created
November 3, 2023 16:02
-
-
Save zawhtutwin/0c70c054445d966c714e29b1e27906a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
MyInfo v4 required JWKS and two certs(one for signing and one for encoding) | |
Following code will print out signing cert and encoding certs. | |
It will also print out the whole JWKS. | |
**/ | |
const jose = require('node-jose'); | |
const crypto = require('crypto'); | |
async function generateKey(){ | |
let key = crypto.generateKeyPairSync('ec', { | |
namedCurve: 'prime256v1', | |
publicKeyEncoding: { | |
type: 'spki', | |
format: 'pem', | |
}, | |
privateKeyEncoding: { | |
type: 'pkcs8', | |
format: 'pem', | |
}, | |
}); | |
let cryptoKey = await jose.JWK.asKey(key.privateKey, 'pem'); | |
console.log(cryptoKey.toPEM(true)); | |
return cryptoKey; | |
} | |
async function generateJwks() { | |
//Creating Signing Key | |
let signingKey = await generateKey(); | |
let publicSigningKeyJSON = signingKey.toJSON(); | |
//Creating Encryption Key | |
let encryptionKey = await generateKey(); | |
let publicEncryptionKeyJSON = encryptionKey.toJSON(); | |
let jwks = { | |
keys: [{...publicSigningKeyJSON, | |
...{use: 'sig'}, | |
...{crv: 'P-256'}, | |
...{alg: 'ES256'}, | |
}, | |
{...publicEncryptionKeyJSON, | |
...{use: 'enc'}, | |
...{crv: 'P-256'}, | |
...{alg: 'ECDH-ES+A256KW'}, | |
}]}; | |
console.log(JSON.stringify(jwks)); | |
} | |
generateJwks(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment