chore(scripts): 新增生成私有公有证书的nodejs脚本
This commit is contained in:
22
scripts/generate_key_pair/main.js
Normal file
22
scripts/generate_key_pair/main.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const crypto = require('crypto');
|
||||
// 生成密钥对
|
||||
const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
|
||||
modulusLength: 3072, // 密钥长度,不少于3072
|
||||
publicKeyEncoding: {
|
||||
type: 'spki', // 公钥编码格式
|
||||
format: 'pem' // 公钥输出格式
|
||||
},
|
||||
privateKeyEncoding: {
|
||||
type: 'pkcs8', // 私钥编码格式
|
||||
format: 'pem' // 私钥输出格式
|
||||
}
|
||||
});
|
||||
console.info('生成的公钥:');
|
||||
console.info(publicKey);
|
||||
console.info('生成的私钥:');
|
||||
console.info(privateKey);
|
||||
|
||||
// 保存密钥对到文件
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('public_key.pem', publicKey);
|
||||
fs.writeFileSync('private_key.pem', privateKey);
|
||||
Reference in New Issue
Block a user