sign.sign(privateKey[, outputEncoding])
privateKey<Object> | <string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> | <KeyObject> | <CryptoKey>outputEncoding<string> 返回值的编码。- 返回:<Buffer> | <string>
使用 sign.update() 或 sign.write() 对传入的所有数据计算签名。
🌐 Calculates the signature on all the data passed through using either
sign.update() or sign.write().
如果 privateKey 不是 KeyObject,则此函数的行为就像 privateKey 已被传递给 crypto.createPrivateKey()。如果它是一个对象,则可以传入以下附加属性:
🌐 If privateKey is not a KeyObject, this function behaves as if
privateKey had been passed to crypto.createPrivateKey(). If it is an
object, the following additional properties can be passed:
-
dsaEncoding<string> 对于 DSA 和 ECDSA,此选项指定生成的签名的格式。它可以是以下之一:'der'(默认):DER 编码的 ASN.1 签名结构编码(r, s)。'ieee-p1363':IEEE-P1363 提出的签名格式r || s。
-
padding<integer> RSA 的可选填充值,以下之一:crypto.constants.RSA_PKCS1_PADDING(默认)crypto.constants.RSA_PKCS1_PSS_PADDING
RSA_PKCS1_PSS_PADDING将使用 MGF1,其哈希函数与用于签署消息的哈希函数相同,如 RFC 4055 第 3.1 节所述,除非已根据 RFC 4055 第 3.3 节的要求,在密钥中指定了 MGF1 哈希函数。 -
saltLength<integer> 当填充为RSA_PKCS1_PSS_PADDING时的盐长度。特殊值crypto.constants.RSA_PSS_SALTLEN_DIGEST将盐长度设置为摘要大小,crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN(默认)将其设置为最大允许值。
如果提供了 outputEncoding,则返回一个字符串;否则返回一个 Buffer。
🌐 If outputEncoding is provided a string is returned; otherwise a Buffer
is returned.
Sign 对象在调用 sign.sign() 方法后不能再次使用。多次调用 sign.sign() 会导致抛出错误。
🌐 The Sign object can not be again used after sign.sign() method has been
called. Multiple calls to sign.sign() will result in an error being thrown.