rsaGenerateKey()
function rsaGenerateKey(modulusLength?): Promise<{
privateKey: string;
publicKey: string;
}>;
Defined in: crypto/rsaGenerateKey.ts:33
生成 RSA 密钥对
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
modulusLength | number | 1024 | 模数长度,默认 1024,可选值:1024、2048、4096 |
Returns
Promise<{
privateKey: string;
publicKey: string;
}>
包含公钥和私钥 PEM 格式字符串的对象
Throws
当密钥生成失败时抛出错误
Example
const keyPair = await rsaGenerateKey(2048);
console.log(keyPair.publicKey); // PEM 格式的公钥
console.log(keyPair.privateKey); // PEM 格式的私钥
**Note:** 使用 Web Crypto API 生成 RSA-OAEP 密钥对
**Note:** 使用 SHA-512 哈希算法
**Note:** 公钥指数固定为 65537 (0x010001)
**Note:** 生成的密钥可用于加密和解密操作