keyObject.export([options])
对于对称密钥,可以使用以下编码选项:
¥For symmetric keys, the following encoding options can be used:
对于公钥,可以使用以下编码选项:
¥For public keys, the following encoding options can be used:
-
type<string> 必须是'pkcs1'(仅限 RSA)或'spki'之一。¥
type<string> Must be one of'pkcs1'(RSA only) or'spki'. -
format<string> 必须是'pem'、'der'或'jwk'。¥
format<string> Must be'pem','der', or'jwk'.
对于私钥,可以使用以下编码选项:
¥For private keys, the following encoding options can be used:
-
type<string> 必须是'pkcs1'(仅限 RSA)、'pkcs8'或'sec1'(仅限 EC)之一。¥
type<string> Must be one of'pkcs1'(RSA only),'pkcs8'or'sec1'(EC only). -
format<string> 必须是'pem'、'der'或'jwk'。¥
format<string> Must be'pem','der', or'jwk'. -
cipher<string> 如果指定,私钥将使用给定的cipher和passphrase使用基于 PKCS#5 v2.0 密码的加密进行加密。¥
cipher<string> If specified, the private key will be encrypted with the givencipherandpassphraseusing PKCS#5 v2.0 password based encryption. -
passphrase<string> | <Buffer> 用于加密的密码,请参阅cipher。¥
passphrase<string> | <Buffer> The passphrase to use for encryption, seecipher.
结果类型取决于所选的编码格式,当 PEM 时结果是字符串,当 DER 时它将是包含编码为 DER 的数据的缓冲区,当 JWK 时它将是对象。
¥The result type depends on the selected encoding format, when PEM the result is a string, when DER it will be a buffer containing the data encoded as DER, when JWK it will be an object.
选择 JWK 编码格式时,将忽略所有其他编码选项。
¥When JWK encoding format was selected, all other encoding options are ignored.
PKCS#1、SEC1 和 PKCS#8 类型的密钥可以通过使用 cipher 和 format 选项的组合进行加密。PKCS#8 type 可以与任何 format 一起使用,通过指定 cipher 来加密任何密钥算法(RSA、EC 或 DH)。当使用 PEM format 时,PKCS#1 和 SEC1 只能通过指定 cipher 来加密。为了获得最大的兼容性,对加密的私钥使用 PKCS#8。由于 PKCS#8 定义了自己的加密机制,因此在加密 PKCS#8 密钥时不支持 PEM 级加密。有关 PKCS#8 加密的信息,请参阅 RFC 5208,有关 PKCS#1 和 SEC1 加密的信息,请参阅 RFC 1421。
¥PKCS#1, SEC1, and PKCS#8 type keys can be encrypted by using a combination of
the cipher and format options. The PKCS#8 type can be used with any
format to encrypt any key algorithm (RSA, EC, or DH) by specifying a
cipher. PKCS#1 and SEC1 can only be encrypted by specifying a cipher
when the PEM format is used. For maximum compatibility, use PKCS#8 for
encrypted private keys. Since PKCS#8 defines its own
encryption mechanism, PEM-level encryption is not supported when encrypting
a PKCS#8 key. See RFC 5208 for PKCS#8 encryption and RFC 1421 for
PKCS#1 and SEC1 encryption.