好吧,所以我有一个名为kryptert的文本文件,该文件已加密。带有私钥的名为私有的密钥文件。我希望输出在名为Klartext的文本文件中。
我即将撕开头发,因为我似乎无法弄清楚。
openssl rsautl -decrypt -inkey C:private.key -in C:Kryptert.txt -out C:Klartext.txt
上面的命令是我使用的,我在CMD Windows中获得以下输出:
C:UsersMarco>openssl rsautl -decrypt -inkey C:private.key -in C:Kryptert.txt -out C:Klartext.txt
Loading 'screen' into random state - done
RSA operation error
8560:error:0407106B:rsa routines:RSA_padding_check_PKCS1_type_2:block type is not 02:.cryptorsarsa_pk1.c:190:
8560:error:04065072:rsa routines:RSA_EAY_PRIVATE_DECRYPT:padding check failed:.cryptorsarsa_eay.c:592:
有人能够帮助我了解什么问题以及如何解决问题?谢谢。
在这里您需要使用openssl加密或解密的命令:
解密:
$ openssl rsautl -decrypt -in $ENCRYPTED -out $PLAINTEXT -inkey keys/privkey.pem
加密:
$ openssl rsautl -encrypt -in $PLAINTEXT -out $PLAINTEXT.encrypt -pubin -inkey keys/pubkey.pem
希望这会有所帮助!:)
用于加密:
openssl rsautl -encrypt -in /path/to/your/file -out /path/to/your/encrypted -pubin -inkey /path/to/your/public_key.pem
解密:
openssl rsautl -decrypt -in /path/to/your/encrypted -out /path/where/you/want/your/decrypted.txt -inkey /path/to/your/private_key.pem
注意:如果您有此解密错误:RSA_EAY_PRIVATE_DECRYPT:data greater than mod len
在解密文件之前先尝试此命令:
cat yourEncryptedFile| base64 -D > yourEncryptedRawFile
更多信息在这里
对于版本3.0及更高版本rsautil
已弃用。改用pkeyutl
。对于此示例,(在Windows上)的用法保持不变:
.openssl.exe pkeyutl -decrypt -in .encryptedfile -out decryptedfile -inkey .private-key.pem
旁注:我正在与TLS一起玩,并想解密客户在TLS 1.0(是,TLS 1.0)握手中发送的主机键。如果某人尝试相同的话:将主机密钥(将以十六进制表示)复制到文本文件中,将其保存,然后使用certutil
将文本文件转换为二进制文件。然后可以与OpenSSL一起使用。
示例:
- 将premaster Key的十六进制表示为二进制:
certutil -decodehex -f .premasterkey.txt premasterkey.bin
- 使用openssl解密
.openssl.exe pkeyutl -decrypt -in .premasterkey.bin -out decrypted.bin -inkey .private-key.pem
- (可选)再次将结果二进制转换为十六进制表示形式。
certutil -encodehex -f decrypted.bin decryptedinhex.txt