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':签名格式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 节所规定,除非已根据 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.】