crypto.verify(algorithm, data, key, signature)
algorithm<string> | <null> | <undefined>data<Buffer> | <TypedArray> | <DataView>key<Object> | <string> | <Buffer> | <KeyObject>signature<Buffer> | <TypedArray> | <DataView>- 返回: <boolean>
使用给定的密钥和算法验证 data 的给定签名。
如果 algorithm 是 null 或 undefined,则算法取决于密钥类型(尤其是 Ed25519 和 Ed448)。
如果 key 不是 KeyObject,则此函数的行为就像将 key 传给 crypto.createPublicKey() 一样。
如果是对象,则可以传入以下额外属性:
-
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 节中指定的那样。 -
saltLength<integer> 填充为RSA_PKCS1_PSS_PADDING时的盐长度。 特殊值crypto.constants.RSA_PSS_SALTLEN_DIGEST将盐长度设置为摘要大小,crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN(默认值)将其设置为最大允许值。
signature 参数是先前为 data 计算的签名。
因为公钥可以从私钥派生出来,所以可以为 key 传入私钥或公钥。
algorithm<string> | <null> | <undefined>data<Buffer> | <TypedArray> | <DataView>key<Object> | <string> | <Buffer> | <KeyObject>signature<Buffer> | <TypedArray> | <DataView>- Returns: <boolean>
Verifies the given signature for data using the given key and algorithm. If
algorithm is null or undefined, then the algorithm is dependent upon the
key type (especially Ed25519 and Ed448).
If key is not a KeyObject, this function behaves as if key had been
passed to crypto.createPublicKey(). If it is an object, the following
additional properties can be passed:
-
dsaEncoding<string> For DSA and ECDSA, this option specifies the format of the signature. It can be one of the following:'der'(default): DER-encoded ASN.1 signature structure encoding(r, s).'ieee-p1363': Signature formatr || sas proposed in IEEE-P1363.
-
padding<integer> Optional padding value for RSA, one of the following:crypto.constants.RSA_PKCS1_PADDING(default)crypto.constants.RSA_PKCS1_PSS_PADDING
RSA_PKCS1_PSS_PADDINGwill use MGF1 with the same hash function used to sign the message as specified in section 3.1 of RFC 4055. -
saltLength<integer> Salt length for when padding isRSA_PKCS1_PSS_PADDING. The special valuecrypto.constants.RSA_PSS_SALTLEN_DIGESTsets the salt length to the digest size,crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN(default) sets it to the maximum permissible value.
The signature argument is the previously calculated signature for the data.
Because public keys can be derived from private keys, a private key or a public
key may be passed for key.