Object built-in object

Object Digest

infosummary object

inheritance relationship

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<this>Digest|size|update();digest();sign();verify()] [object] <:- [Digest] Digest size update() digest() sign() verify() object toString() toJSON()

Member properties

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, binary data block

Return result:

  • Digest, returns the message digest object itself

digest

Calculate and return a summary

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

Call parameters:

  • codec: String, specifies the encoding format, the 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 the digest

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

Call parameters:

  • key:PKey, the signed private key
  • 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, the public key to verify the signature
  • sign:Buffer, specifying the signature to verify
  • opts: Object, specify validation 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

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

1
String Digest.toString();

Return result:

  • String, returns the string representation of the object

toJSON

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

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

Call parameters:

  • key: String, unused

Return result:

  • Value, returns a value containing JSON serializable