mac.final([outputEncoding])
完成 MAC 计算并返回认证标签。如果 outputEncoding 被省略或为 'buffer',则返回 Buffer。否则,将返回一个字符串。
🌐 Completes the MAC computation and returns the authentication tag. If
outputEncoding is omitted or is 'buffer', a Buffer is returned.
Otherwise, a string is returned.
要验证身份验证标签,使用 crypto.timingSafeEqual() 比较相同长度的 Buffer 值。
🌐 To verify an authentication tag, compare equal-length Buffer values using
crypto.timingSafeEqual().
Mac 对象在尝试进行终结后就不能再使用,包括终结失败的情况。之后调用 mac.update() 或 mac.final() 会抛出 ERR_CRYPTO_MAC_FINALIZED。
🌐 The Mac object cannot be used again after finalization is attempted,
including when finalization fails. Later calls to mac.update() or
mac.final() throw ERR_CRYPTO_MAC_FINALIZED.