From 39ce5882cbc7654863c2d9ee5c6eec94fc91ffa7 Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Mon, 1 Dec 2025 15:27:30 +0800 Subject: [PATCH] =?UTF-8?q?chore(scripts):=20=E6=96=B0=E5=A2=9E=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=A7=81=E6=9C=89=E5=85=AC=E6=9C=89=E8=AF=81=E4=B9=A6?= =?UTF-8?q?=E7=9A=84nodejs=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/generate_key_pair/main.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/generate_key_pair/main.js diff --git a/scripts/generate_key_pair/main.js b/scripts/generate_key_pair/main.js new file mode 100644 index 000000000..04c248314 --- /dev/null +++ b/scripts/generate_key_pair/main.js @@ -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); \ No newline at end of file