Object built-in object

Object Digest

Information Digest Object

inheritance relationship

member attribute

size

Integer, query the number of digest bytes of the current message digest algorithm

1
readonly Integer Digest.size;

member function

update

Update binary digest information

1
Digest Digest.update(Buffer data);

Call parameters:

  • data:Buffer, the binary data block

return result:

  • Digest, returns the information summary object itself

digest

Compute and return a summary

1
Value Digest.digest(String codec = "buffer");

Call parameters:

  • codec: String, specifies the encoding format, allowed values ​​are: "buffer", "hex", "base32", "base58", "base64", "utf8", oriconvCharacter sets supported by the module

return result:

  • Value, returns a digest representation of the specified encoding

sign

Sign and return digest

1 2
Buffer Digest.sign(PKey key, Object opts = {}) async;

Call parameters:

  • key:PKey, the private key to sign
  • opts: Object, specifies signature options

return result:

  • Buffer, returns the signed data

opts supports the following parameters:

1 2 3 4 5 6 7 8 9 10 11 12
{ alg: 0, 指定签名的 hash 算法, 仅在 RSA 时有效, 缺省为 0. 支持算法: 0 = NONE, 1 = MD5, 2 = SHA1, 3 = SHA224, 4 = SHA256, 5 = SHA384, 6 = SHA512, 7 = RIPEMD160 to: pk, 指定验证方公钥, 仅在 ecsdsa 或 sm2 时有效 }

verify

Verify that the signatures are consistent

1 2 3
Boolean Digest.verify(PKey key, Buffer sign, Object opts = {}) async;

Call parameters:

  • key:PKey, to verify the signed public key
  • sign:Buffer, specifying the signature to verify
  • opts: Object, specifies the authentication options

return result:

  • Boolean, returns the verified result

opts supports the following parameters:

1 2 3 4 5 6 7 8 9 10 11 12
{ alg: 0, 指定签名的 hash 算法, 仅在 RSA 时有效, 缺省为 0. 支持算法: 0 = NONE, 1 = MD5, 2 = SHA1, 3 = SHA224, 4 = SHA256, 5 = SHA384, 6 = SHA512, 7 = RIPEMD160 to: pk, 指定验证方公钥, 仅在 ecsdsa 或 sm2 时有效 }

toString

Return the string representation of the object, generally return "[Native Object]", the object can be reimplemented according to its own characteristics

1
String Digest.toString();

return result:

  • String, returns a string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable properties defined by the object

1
Value Digest.toJSON(String key = "");

Call parameters:

  • key: String, not used

return result:

  • Value, which returns a JSON-serializable value