crypto.sign(algorithm, data, key[, callback])
算法<string> | <null> | <undefined>数据<ArrayBuffer> | <Buffer> | <TypedArray> | <DataView>密钥<Object> | <string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> | <KeyObject> | <CryptoKey>回调<Function>- 返回: 如果未提供
callback函数,则返回 <Buffer>。
使用给定的私钥和算法计算并返回 data 的签名。如果 algorithm 为 null 或 undefined,则算法将取决于密钥类型(尤其是 Ed25519 和 Ed448)。
【Calculates and returns the signature for data using the given private key and
algorithm. If algorithm is null or undefined, then the algorithm is
dependent upon the key type (especially Ed25519 and Ed448).】
如果 key 不是 KeyObject,此函数的行为就像将 key 传给 crypto.createPrivateKey() 一样。如果它是一个对象,则可以传递以下附加属性:
【If key is not a KeyObject, this function behaves as if key 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':签名格式r || s,如 IEEE-P1363 所提议。
-
padding<integer> RSA 的可选填充值,可以是以下之一:crypto.constants.RSA_PKCS1_PADDING(默认)crypto.constants.RSA_PKCS1_PSS_PADDING
RSA_PKCS1_PSS_PADDING将使用与签名消息相同的哈希函数的 MGF1,如 RFC 4055 第 3.1 节所述。 -
saltLength<integer> 当填充方式为RSA_PKCS1_PSS_PADDING时的盐长度。特殊值crypto.constants.RSA_PSS_SALTLEN_DIGEST会将盐长度设置为摘要大小,crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN(默认值)设置为允许的最大值。
如果提供了 callback 函数,该函数会使用 libuv 的线程池。
【If the callback function is provided this function uses libuv's threadpool.】