openssl aes gcm 加密,带认证标签;命令行
openssl aes gcm encryption with authentication TAG; command line
我正在尝试使用 'openssl' 命令行
在 AES-GCM 模式下加密文件
openssl enc -aes-256-gcm -p -iv 000000000000000000000000 -K 00000000000000000000000000000000000000000000000000000000000000 -nosalt -in file.raw -out file.enc`
加密有效,但我找不到检索生成的 GCM 标记的方法。
有办法得到吗?
在这篇文档 (link) 中我找到了 "Note that it is now even possible to use authenticated mode like CCM or GCM" 但仍然有 none 信息如何做到这一点。
或者是否有任何其他标准的 macos 工具可以完成同样的工作?
PS:我很感兴趣通过常见的分布式命令行工具来做到这一点,这不是编写自己的实用程序的问题
注意:正如用户 dave_thompson_085 在下面指出的那样,答案其余部分的结果与当前版本的 OpenSSL 无关。我不小心使用了 LibreSSL openssl
。阅读当前版本的OpenSSL documentation for the enc
tool,它包含以下句子
The enc program does not support authenticated encryption modes like
CCM and GCM. The utility does not store or retrieve the authentication
tag.
我想这回答了您的问题 -- 取决于您使用的 OpenSSL 版本。
原始答案,使用 macOS 附带的 LibreSSL openssl
获得:
使用 openssl enc
应用程序时,GCM 标签未存储在输出文件中。从下面一行就可以看出来:
$ echo -n 'abcdefghijklmnop' | openssl enc -aes-256-gcm -K 0 -iv 0 | hexdump -C
00000000 af c5 23 59 28 06 0c 06 6e 24 ae bf d7 9d f2 68 |..#Y(...n$.....h|
00000010
输出的大小与输入的大小完全相同,任何地方都没有标记字节。
您也可以通过检查实现来查看它 enc.c. It does not do any EVP_CIPHER_CTX_ctrl()
call to deal with the GCM tag, as explained in the OpenSSL Wiki page on EVP Authenticated Encryption and Decryption。换句话说,他的标签数据丢失了。
在使用 aes-256-gcm
解密时,工具本身也会忽略标签的缺失。一条消息 bad decrypt
被发送到 stderr
但它似乎来自与应用程序不同的层,它愉快地打印结果:
$ echo -n 'abcdefghijklmnop' | openssl enc -aes-256-gcm -K 0 -iv 0 | openssl enc -aes-256-gcm -K 0 -iv 0 -d
bad decrypt
abcdefghijklmnop
此帖发布已久,但对于其他人:
"commonly available command line tools"时,AES GCM 不可用。最接近的可能是 AESCRYPT,它具有文档化文件格式和多种语言实现的优势。有关详细信息,请参阅 aescrypt.com。
根据 OpenSSL man page 支持的密码:
The enc program does not support authenticated encryption modes like
CCM and GCM, and will not support such modes in the future.
我正在尝试使用 'openssl' 命令行
在 AES-GCM 模式下加密文件openssl enc -aes-256-gcm -p -iv 000000000000000000000000 -K 00000000000000000000000000000000000000000000000000000000000000 -nosalt -in file.raw -out file.enc`
加密有效,但我找不到检索生成的 GCM 标记的方法。 有办法得到吗?
在这篇文档 (link) 中我找到了 "Note that it is now even possible to use authenticated mode like CCM or GCM" 但仍然有 none 信息如何做到这一点。
或者是否有任何其他标准的 macos 工具可以完成同样的工作?
PS:我很感兴趣通过常见的分布式命令行工具来做到这一点,这不是编写自己的实用程序的问题
注意:正如用户 dave_thompson_085 在下面指出的那样,答案其余部分的结果与当前版本的 OpenSSL 无关。我不小心使用了 LibreSSL openssl
。阅读当前版本的OpenSSL documentation for the enc
tool,它包含以下句子
The enc program does not support authenticated encryption modes like CCM and GCM. The utility does not store or retrieve the authentication tag.
我想这回答了您的问题 -- 取决于您使用的 OpenSSL 版本。
原始答案,使用 macOS 附带的 LibreSSL openssl
获得:
使用 openssl enc
应用程序时,GCM 标签未存储在输出文件中。从下面一行就可以看出来:
$ echo -n 'abcdefghijklmnop' | openssl enc -aes-256-gcm -K 0 -iv 0 | hexdump -C
00000000 af c5 23 59 28 06 0c 06 6e 24 ae bf d7 9d f2 68 |..#Y(...n$.....h|
00000010
输出的大小与输入的大小完全相同,任何地方都没有标记字节。
您也可以通过检查实现来查看它 enc.c. It does not do any EVP_CIPHER_CTX_ctrl()
call to deal with the GCM tag, as explained in the OpenSSL Wiki page on EVP Authenticated Encryption and Decryption。换句话说,他的标签数据丢失了。
在使用 aes-256-gcm
解密时,工具本身也会忽略标签的缺失。一条消息 bad decrypt
被发送到 stderr
但它似乎来自与应用程序不同的层,它愉快地打印结果:
$ echo -n 'abcdefghijklmnop' | openssl enc -aes-256-gcm -K 0 -iv 0 | openssl enc -aes-256-gcm -K 0 -iv 0 -d
bad decrypt
abcdefghijklmnop
此帖发布已久,但对于其他人:
"commonly available command line tools"时,AES GCM 不可用。最接近的可能是 AESCRYPT,它具有文档化文件格式和多种语言实现的优势。有关详细信息,请参阅 aescrypt.com。
根据 OpenSSL man page 支持的密码:
The enc program does not support authenticated encryption modes like CCM and GCM, and will not support such modes in the future.