mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-16 10:11:54 +01:00
c2370a1be6
* chore: Add the SPDX information to each file Add copyright and licensing information as defined in version 3.0 of the REUSE Specification. * tweak format --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
41 lines
911 B
TypeScript
41 lines
911 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
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,
|
|
},
|
|
});
|
|
}
|