如何在 AES 加密中使用随机随机数解密

how to decrypt with random nonce in AES encryption

我是密码学新手。我需要使用带有某些配置的 AES 加密文本

Encryption mode: GCM
Key size: 256 bits
Nonce size: 96 bits
MAC size: 128 bits

因为 AES 是一种对称算法。所以我有一个秘钥。我用谷歌搜索并找到

nonce is a random number used to make sure a message is unique

但我有疑问,如果 nonce 是一个随机数,我该如何进行解密。我需要将随机数与每次加密一起存储吗?或者我需要使用密钥拆分随机数、密码和 mac 的任何其他方式。 我如何使用提供的配置进行加密。

准确的说,nonce必须和密文一起存储

请记住,随机数作为密文的一部分不会给攻击者带来任何优势。

来自维基百科:

An initialization vector has different security requirements than a key, so the IV usually does not need to be secret. However, in most cases, it is important that an initialization vector is never reused under the same key. For CBC and CFB, reusing an IV leaks some information about the first block of plaintext, and about any common prefix shared by the two messages.

初始化向量的目的是在加密过程中插入一些随机性,这样攻击者就无法知道何时用相同的密钥加密了两个相同的明文消息。

解密需要IV,您只需将其与密文连接发送即可。

IV || ciphertext

传输初始化向量的最常见方式确实是将其紧接在密文之前。

But i have a doubt, how i can perform decryption, if nonce is a random number. do i need to store nonce along with each encryption.

是,加密的结果stored/sent是随机数,密文,mac。

how i can perform decryption, if nonce is a random number

Nonce 是在加密输入时随机生成的,然后随密文传递 nonce(通常将 nonce 作为第一个块添加到前面)。确实你在解密时需要相同的 nonce 值,然后 nonce 是解密输入的一部分,而不是随机

or any other way i need to split nonce, cipher and mac using key. how can i use the provided configuration for encryption.

有一个 standardized message format for encrypted document or encrypted XML messages,但这些都非常复杂。

实际上 - 对于更简单的应用程序,我们经常看到加密输出组成为 IV || ciphertext || MAC(作为串联)。 IV和MAC都是定长的,可以剪下来用参数解密。

decryption is happening on different machine and language. they have shared only a key for encryption. same key they are using for decryption. if i will add any random value as nonce then how hey will know what logic i have used for nonc

在您提供相同的输入之前,这并不重要。如前所述 - 您可以将 IV(随机数)作为消息的一部分传递,并在解密之前将随机数和原始密文分开。

顺便说一句:我有 a few encryption examples 链接