Linux

使用 AES256 加密時 GnuPG 和 OpenSSL 的不同結果

  • May 1, 2012

文字:apple 密碼:密碼

openssl aes-256-cbc -e -a -in  apple.txt

輸出:U2FsdGVkX1/sqDrVkgk/7dKiCfLW+1/bgvRT/YAopJQ=

gpg -c --cipher-algo AES256 apple.txt

輸出:A0ECQMCvDw3qeyQxgNg0kABv5nE4IDtSYmDTJudbl55d0GjBkiLd1B4sgbY/QQPVJX/uaHuDIb9 xhcwW/7UaxIxh9URhkHPni2IhYoOuKqm

如何同步出兩個結果?

openssl命令將您的輸入加鹽並將其放入 OpenSSL 加密容器中。您可以使用該-nosalt選項,但它會降低加密的安全性。我對gpg命令知之甚少,但我很確定它正在做類似的事情。它的輸出太大而不能僅僅加密“蘋果”這個詞。

事件如果您在不同時間使用相同的命令,您將有不同的輸出。原因是每次生成新的 AES-256 密鑰並使用您的密碼進行保護。

openssl aes-256-cbc -e -a -in  password.txt
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
U2FsdGVkX19yNQwed5/Sq3b6/3UFGGOGVD1dSA7aCZI=

openssl aes-256-cbc -e -a -in  password.txt
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
U2FsdGVkX19rulpZRi8u5K9iJKVN5FVFRb6ngFY1BWM=

openssl aes-256-cbc -e -a -in  password.txt
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
U2FsdGVkX192MxevxHvc1wW0dh9P4HctQF/75HEPVB4=

openssl enc -aes-256-cbc -k test -P
salt=667E42EDE61BEA35
key=46FB1D91FC400A8E26A8B0E38CF505F026263299CF0FA541217FBC6CEED1FC0B
iv =10A3858EC9D718AB91FC45B98786FDCC

openssl enc -aes-256-cbc -k test -P
salt=34F9B481E391A831
key=CDF1D936F99147BB56B4E3441B5E1A68A15838FE43F234AA7EB9A9F903B0BD61
iv =A649443D096E6976420F4941C2608CC8

openssl enc -aes-256-cbc -k test -P
salt=51AC4B4388D5C25B
key=D70AF8238D1C597F074123C9BB23B76C9CA04AAF2C986C4A56F96CB0FF1365F9
iv =D70FB991EEE776FCD45A67830CBD3202

引用自:https://serverfault.com/questions/367545