mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-27 04:17:51 -07:00
42 lines
810 B
TypeScript
42 lines
810 B
TypeScript
import * as crypto from "node:crypto";
|
|
import * as util from "node:util";
|
|
|
|
const generateKeyPair = util.promisify(crypto.generateKeyPair);
|
|
|
|
export async function genRsaKeyPair(modulusLength = 2048) {
|
|
return await generateKeyPair("rsa", {
|
|
modulusLength,
|
|
publicKeyEncoding: {
|
|
type: "spki",
|
|
format: "pem",
|
|
},
|
|
privateKeyEncoding: {
|
|
type: "pkcs8",
|
|
format: "pem",
|
|
cipher: undefined,
|
|
passphrase: undefined,
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function genEcKeyPair(
|
|
namedCurve:
|
|
| "prime256v1"
|
|
| "secp384r1"
|
|
| "secp521r1"
|
|
| "curve25519" = "prime256v1",
|
|
) {
|
|
return await generateKeyPair("ec", {
|
|
namedCurve,
|
|
publicKeyEncoding: {
|
|
type: "spki",
|
|
format: "pem",
|
|
},
|
|
privateKeyEncoding: {
|
|
type: "pkcs8",
|
|
format: "pem",
|
|
cipher: undefined,
|
|
passphrase: undefined,
|
|
},
|
|
});
|
|
}
|