crypto.verify(algorithm, data, key, signature[, callback])
algorithm<string> | <null> | <undefined>data<ArrayBuffer> | <Buffer> | <TypedArray> | <DataView>key<Object> | <string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> | <KeyObject> | <CryptoKey>signature<ArrayBuffer> | <Buffer> | <TypedArray> | <DataView>callback<Function>- 返回:<boolean>
true或false,取决于数据和公钥的签名是否有效,如果没有提供callback函数。
使用给定的密钥和算法验证 data 的签名。如果 algorithm 为 null 或 undefined,则算法将取决于密钥类型。
🌐 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.
algorithm 对于 Ed25519、Ed448 和 ML-DSA 必须为 null 或 undefined。
如果 key 不是 KeyObject,此函数的行为就像将 key 传给 crypto.createPublicKey() 一样。如果它是一个对象,则可以传递以下附加属性:
🌐 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> 对于 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_PADDINGwill use MGF1 with the same hash function used to sign the message as specified in section 3.1 of RFC 4055. -
saltLength<integer> 当填充为RSA_PKCS1_PSS_PADDING时的盐长度。特殊值crypto.constants.RSA_PSS_SALTLEN_DIGEST将盐长度设置为摘要大小,crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN(默认)将其设置为允许的最大值。 -
context<ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> 对于 Ed448、ML-DSA 和 SLH-DSA,此选项指定可选的上下文,用于区分使用相同密钥为不同目的生成的签名。
signature 参数是之前为 data 计算的签名。
🌐 The signature argument is the previously calculated signature for the data.
因为公钥可以由私钥推导出来,所以可以为 key 提供私钥或公钥。
🌐 Because public keys can be derived from private keys, a private key or a public
key may be passed for key.
如果提供了 callback 函数,该函数会使用 libuv 的线程池。
🌐 If the callback function is provided this function uses libuv's threadpool.