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

标签 encryption cryptography aes nonce

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

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

由于 AES 是一种对称算法。所以我有一个 secret key 。我用谷歌搜索并发现

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



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

最佳答案

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.


是的,存储/发送的加密结果是随机数、密文、mac。

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


加密输入时随机生成随机数,然后随机数随密文传递(通常随机数作为第一个块被添加)。实际上,解密时您需要相同的随机数值,然后随机数是解密输入的一部分,而不是随机数

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用于加密文档或 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链接

关于encryption - 如何在 AES 加密中用随机数解密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59029634/

相关文章:

objective-c - 初学者的AES加密/解密

java - 用 BouncycaSTLe jar 替换 JCE

java - AES 加密尝试失败 - 鉴于最终 block 可能未正确填充

c# - 格式保留加密示例

cryptography - 从 X509 证书读取 RSA 私钥会导致 Windows Server 2016 与 Windows Server 2019 上的不同输出

node.js - 如何使用 cryptoJS 或 Node 的默认加密为 AES 选择密码?

encryption - 为什么私钥不应该逐字或以纯文本形式存储在本地计算机上?

php - 使用 PHP 在 MySQL 数据库中自动加密?

javascript - AES 在 cryptojs 中加密并在 python Crypto.Cipher 中解密

c++ - 使用 Boost::asio::async_send_to 发送加密数据时出错