-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.ts
32 lines (26 loc) · 953 Bytes
/
generator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Request, Response } from "express"
import { JWK } from "node-jose"
const config = {
"RS256": { kty: "RSA", size: 2048 },
"RS384": { kty: "RSA", size: 2048 },
"RS512": { kty: "RSA", size: 2048 },
"ES256": { kty: "EC" , size: "P-256" },
"ES384": { kty: "EC" , size: "P-384" },
"ES512": { kty: "EC" , size: "P-521" }
}
export default async function(req: Request, res: Response) {
let alg = String(req.query.alg || "").toUpperCase();
if (!config.hasOwnProperty(alg)) {
alg = "RS384";
}
const store = JWK.createKeyStore();
const settings = config[alg as keyof typeof config];
const key = await store.generate(settings.kty, settings.size, { alg });
res.json({
jwks : store.toJSON(true),
publicAsJWK : key.toJSON(false),
publicAsPEM : key.toPEM(false),
privateAsJWK: key.toJSON(true),
privateAsPEM: key.toPEM(true)
});
}