저는 지금 당분간이 문제에 봉착했습니다.C에서 OpenSSL RSA 함수를 사용하여 메시지를 암호 해독 할 때
bad decrypt
140380701197976:error:0606506D:digital envelope
routines:EVP_DecryptFinal_ex:wrong final block length:evp_enc.c:518:
때때로, 나는 이러한 오류를 참조하십시오 :
RSA operation error
139986632922776:error:0407109F:rsa routines:RSA_padding_check_PKCS1_type_2:pkcs decoding error:rsa_pk1.c:273:
139986632922776:error:04065072:rsa
routines:RSA_EAY_PRIVATE_DECRYPT:padding check failed:rsa_eay.c:602:
Error reading password from BIO
Error getting password
을 그리고 때때로, 나는 전혀 오류가 표시되지 않습니다 내 프로그램을 실행하면, 때로는 이러한 오류를 참조하십시오! Chrome 하드웨어 용 우분투 (Ubuntu)의 맛 인 GalliumOS를 사용하고 있습니다.
무엇이 누락 되었습니까? 나는 온통 보았고, 나는 관련성이있는 것을 찾을 수 없다. 참고로 아래 코드를 첨부했습니다. 나는 내가 마지막 두 명령 중 하나에 오류를 좁혔다 고 생각하지만, 나는 긍정적이지 않다.
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
string bob_keys, alice_plaintext, alice_encrypted, bob_decrypted;
// ----- USER INPUT -----
// TODO: switch to user input
bob_keys = "bob_keys.pem";
bob_decrypted = "bob_decrypted.txt";
alice_encrypted = "alice_encrypted.txt";
alice_plaintext = "alice_plaintext.txt";
// ----- CONFIDENTIALITY: MESSAGE ENCRYPTION -----
// generate session key
system("openssl rand -base64 64 -out key.bin");
// encrypt message using session key
system(("openssl enc -aes-128-cbc -salt -in " + alice_plaintext
+ " -out alice_plaintext.txt.enc -pass file:./key.bin").c_str());
// encrypt session key using Bob's public key
system(("openssl rsautl -encrypt -inkey " + bob_keys
+ " -pubin -in key.bin -out key.bin.enc").c_str());
// write encrypted message and encrypted session key to file
system(("cat alice_plaintext.txt.enc > " + alice_encrypted).c_str());
system(("echo >> " + alice_encrypted).c_str());
system(("cat key.bin.enc >> " + alice_encrypted).c_str());
// ----- CONFIDENTIALITY: MESSAGE DECRYPTION -----
// get encrypted message and encrypted session key from file (and remove newlines)
system(("head -1 " + alice_encrypted + " > message.bin.enc").c_str());
system("tr -d '\n' <message.bin.enc> temp.bin && mv temp.bin message.bin.enc");
system(("tail -1 " + alice_encrypted + " > key.bin.enc").c_str());
// decrypt the key using Bob's private key
system(("openssl rsautl -decrypt -inkey " + bob_keys
+ " -in key.bin.enc -out key.bin").c_str());
// decrypt the message using the decrypted key
system(("openssl enc -d -aes-128-cbc -in message.bin.enc -out "
+ bob_decrypted + " -pass file:./key.bin").c_str());
return 0;
}
귀하의 코드는 '시스템'에 대한 호출 일뿐입니다. 대신 셸 스크립트를 사용하지 않는 이유는 무엇입니까? – dbush
그래, 그게 내가 생각한거야. 이유가 뭐든간에, 강사들은 우리가 C++ 파일을 제출하기를 원하지만, 시스템 호출을하는 것은 완전히 냉담하다. 나는 그것도 동의하지 않지만 작동한다. – hockeysaint