c#中的AES GCM实现

cra*_*ish 3 c# aes aes-gcm

我正在c#中以GCM模式实现AES密码.我的问题涉及"额外的经过身份验证的数据"(AAD).在以下代码中

http://blogs.msdn.com/b/shawnfa/archive/2009/03/17/authenticated-symmetric-encryption-in-net.aspx

目前还不清楚我应该从哪里获取AAD,以及如何在解密期间检索特定于此加密的AAD:

// Authenticated data becomes part of the authentication tag that is generated during
// encryption, however it is not part of the ciphertext.  That is, when decrypting the
// ciphertext the authenticated data will not be produced.  However, if the
// authenticated data does not match at encryption and decryption time, the
// authentication tag will not validate.
aes.AuthenticatedData = Encoding.UTF8.GetBytes("Additional authenticated data");
Run Code Online (Sandbox Code Playgroud)

任何有关如何使用此AAD的说明都将非常感激.谢谢

Maa*_*wes 10

AAD代表附加的认证数据或附加的相关数据.这是可以与密文一起以明文形式发送的数据.当您执行AEAD密码的组合验证和解密时,密文和AAD都会经过验证,以确保其完整性.

AAD数据不是关键,它只是您可以包含在协议中的普通数据,需要保护其完整性,但不需要(或者,更逻辑地说,没有用)加密.一个很好的例子是加密IP数据包的标题; 如果加密它就不能用它进行路由,如果你不保护它的完整性,攻击者可能会改变消息长度或源地址,而接收者不知道它.

请注意,AEAD密码已在计算身份验证标记时包含IV/nonce.因此不必将其包含在AAD中.AAD通常用于包括发送方,接收方以及可能的消息标识号(如果它们尚未存在于IV中).