关键格式
🌐 Key formats
非对称密钥可以以多种格式表示。推荐的方法是将密钥材料导入 KeyObject 一次,并在所有后续操作中重复使用它,因为这样可以避免重复解析并提供最佳性能。
🌐 Asymmetric keys can be represented in several formats. The recommended
approach is to import key material into a KeyObject once and reuse it
for all subsequent operations, as this avoids repeated parsing and delivers
the best performance.
当 KeyObject 不实用时——例如,当密钥材料在协议消息中到达并且只使用一次时——大多数加密函数也接受 PEM 字符串或直接指定格式和密钥材料的对象。有关每种格式接受的完整选项,请参见 crypto.createPublicKey()、crypto.createPrivateKey() 和 keyObject.export()。
🌐 When a KeyObject is not practical - for example, when key material
arrives in a protocol message and is used only once - most cryptographic
functions also accept a PEM string or an object specifying the format
and key material directly. See crypto.createPublicKey(),
crypto.createPrivateKey(), and keyObject.export() for the full
options accepted by each format.