如何使用 BouncyCastle 轻量级 API 在 GCM 密码中使用 AAD
How to utilize AAD in GCM cipher using BouncyCastle lightweight API
在加密期间,为 MACing 添加 AAD 似乎只是使用 AEADParameters
。但是不知道以后哪里可以买到这块AAD
我认为processAADBytes
is most likely what I am looking for. processAADBytes
说
If the implementation supports it, this will be an online operation
and will not retain the associated data.
我对此感到困惑。我对此方法有两种可能的解释:
- 这是在加密时传入AAD的另一种方式(除
AEADParameters
外),AAD不会与密文一起存储。
- 这是一种在解密过程中验证AAD的方法。 AAD(来自其他地方)需要在此处提供以进行 MAC 验证。
我曾期望找到像 getAAD()
这样的方法。所以我猜这个密码根本不存储AAD和密文,只是对我们声称是AAD的数据提供MAC验证?
- This is an alternative way to pass in AAD during encryption (in addition to AEADParameters), and the AAD will not be stored with cipher text.
没错,一般来说 AEADParameters
的处理方式与 processAADBytes
中的数据相同。 AAD 可能并不总是必须在 *1 前面提供,它可能包含大量数据(尽管通常不会)。这意味着 processAADBytes
比 AEADParameters
更灵活,因为它允许流式传输并且不需要同时缓冲所有 AAD。
另一方面,AEADParameters
可能有助于向后兼容,并且可能是更 efficient/cleaner 的设计。
- This is a method to verify AAD during decryption. The AAD (from somewhere else) needs to be fed here for MAC verification.
嗯,是的,通常是这样,但您也可以在这里使用 AEADParameters
。
所以两者都是正确的。是的,您需要确保消息的接收者收到(and/or 能够生成)AAD。
*1 EAX 允许随时提供 AAD,如果您在 encryption/decryption 开始后提供 AAD,则 GCM 需要额外的计算(模幂!)。 CCM 需要所有 AAD 前期。如果可以,您应该在encryption/decryption之前提供所有AAD。
在加密期间,为 MACing 添加 AAD 似乎只是使用 AEADParameters
。但是不知道以后哪里可以买到这块AAD
我认为processAADBytes
is most likely what I am looking for. processAADBytes
说
If the implementation supports it, this will be an online operation and will not retain the associated data.
我对此感到困惑。我对此方法有两种可能的解释:
- 这是在加密时传入AAD的另一种方式(除
AEADParameters
外),AAD不会与密文一起存储。 - 这是一种在解密过程中验证AAD的方法。 AAD(来自其他地方)需要在此处提供以进行 MAC 验证。
我曾期望找到像 getAAD()
这样的方法。所以我猜这个密码根本不存储AAD和密文,只是对我们声称是AAD的数据提供MAC验证?
- This is an alternative way to pass in AAD during encryption (in addition to AEADParameters), and the AAD will not be stored with cipher text.
没错,一般来说 AEADParameters
的处理方式与 processAADBytes
中的数据相同。 AAD 可能并不总是必须在 *1 前面提供,它可能包含大量数据(尽管通常不会)。这意味着 processAADBytes
比 AEADParameters
更灵活,因为它允许流式传输并且不需要同时缓冲所有 AAD。
另一方面,AEADParameters
可能有助于向后兼容,并且可能是更 efficient/cleaner 的设计。
- This is a method to verify AAD during decryption. The AAD (from somewhere else) needs to be fed here for MAC verification.
嗯,是的,通常是这样,但您也可以在这里使用 AEADParameters
。
所以两者都是正确的。是的,您需要确保消息的接收者收到(and/or 能够生成)AAD。
*1 EAX 允许随时提供 AAD,如果您在 encryption/decryption 开始后提供 AAD,则 GCM 需要额外的计算(模幂!)。 CCM 需要所有 AAD 前期。如果可以,您应该在encryption/decryption之前提供所有AAD。