verify.verify(object, signature[, signatureEncoding])
object<Object> | <string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> | <KeyObject> | <CryptoKey>signature<string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView>signatureEncoding<string>signature字符串的 编码。- 返回:<boolean>
true或false,取决于数据和公钥签名的有效性。
使用提供的 object 和 signature 验证提供的数据。
🌐 Verifies the provided data using the given object and signature.
如果 object 不是 KeyObject,此函数的行为就好像将 object 传递给了 crypto.createPublicKey()。如果它是一个对象,可以传递以下附加属性:
🌐 If object is not a KeyObject, this function behaves as if
object 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':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_AUTO(默认)则会自动确定盐长度。
signature 参数是数据之前计算得到的签名,使用的是 signatureEncoding。如果指定了 signatureEncoding,signature 预计应为字符串;否则,signature 预计应为 Buffer、TypedArray 或 DataView。
🌐 The signature argument is the previously calculated signature for the data, in
the signatureEncoding.
If a signatureEncoding is specified, the signature is expected to be a
string; otherwise signature is expected to be a Buffer,
TypedArray, or DataView.
verify 对象在调用 verify.verify() 之后不能再次使用。多次调用 verify.verify() 会导致抛出错误。
🌐 The verify object can not be used again after verify.verify() has been
called. Multiple calls to verify.verify() will result in an error being
thrown.
因为可以从私钥推导出公钥,所以可以传递私钥而不是公钥。
🌐 Because public keys can be derived from private keys, a private key may be passed instead of a public key.