decipher.setAuthTag(buffer[, encoding])


在使用经过认证的加密模式(目前支持 GCM、CCM、OCB、SIV、GCM-SIV 和 chacha20-poly1305)时,使用 decipher.setAuthTag() 方法传入收到的 认证标签。如果没有提供标签,或者密文被篡改,decipher.final() 会抛出异常,表示密文应该被丢弃,因为认证失败。如果标签长度根据 NIST SP 800-38D 无效,或者与 authTagLength 选项的值不匹配,decipher.setAuthTag() 会抛出错误。

🌐 When using an authenticated encryption mode (GCM, CCM, OCB, SIV, GCM-SIV, and chacha20-poly1305 are currently supported), the decipher.setAuthTag() method is used to pass in the received authentication tag. If no tag is provided, or if the cipher text has been tampered with, decipher.final() will throw, indicating that the cipher text should be discarded due to failed authentication. If the tag length is invalid according to NIST SP 800-38D or does not match the value of the authTagLength option, decipher.setAuthTag() will throw an error.

decipher.setAuthTag() 方法必须在 CCM、SIV 和 GCM-SIV 模式下调用 decipher.update() 之前,或者在 GCM 和 OCB 模式以及 chacha20-poly1305 下调用 decipher.final() 之前。decipher.setAuthTag() 只能调用一次。

🌐 The decipher.setAuthTag() method must be called before decipher.update() for CCM, SIV, and GCM-SIV modes or before decipher.final() for GCM and OCB modes and chacha20-poly1305. decipher.setAuthTag() can only be called once.

在将字符串作为认证标签传递时,请考虑 将字符串用作加密 API 输入时的注意事项。

🌐 When passing a string as the authentication tag, please consider caveats when using strings as inputs to cryptographic APIs.