1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
unsigned char* Rsa::ossl_encryptWithPrKey (const unsigned char *data, int dataSize, int& newSize) {
unsigned char* encData = new unsigned char[RSA_size(keypair)];
newSize = RSA_private_encrypt(dataSize, data, encData, keypair, RSA_PKCS1_PADDING);
if (newSize == -1) {
char* err = (char*) malloc(130);
ERR_load_crypto_strings();
ERR_error_string(ERR_get_error(), err);
fprintf(stderr, "Error encrypting message: %s\n", err);
free(err);
return nullptr;
}
return encData;
}
unsigned char* Rsa::ossl_decryptWithPrKey (const unsigned char *encData, int dataSize, int& newSize) {
unsigned char *data = new unsigned char[RSA_size(keypair)];
newSize = RSA_private_decrypt(RSA_size(keypair), encData, data, keypair, RSA_PKCS1_OAEP_PADDING);
if (newSize == -1) {
char* err = (char*) malloc(130);
ERR_load_crypto_strings();
ERR_error_string(ERR_get_error(), err);
fprintf(stderr, "Error encrypting message: %s\n", err);
free(err);
return nullptr;
}
return data;
}
unsigned char* Rsa::ossl_encryptWithPbKey (const unsigned char *data,int dataSize, int& newSize) {
unsigned char *encData = new unsigned char[RSA_size(keypair)];
newSize = RSA_public_encrypt(dataSize, data, encData, keypair, RSA_PKCS1_OAEP_PADDING);
if (newSize == -1) {
char* err = (char*) malloc(130);
ERR_load_crypto_strings();
ERR_error_string(ERR_get_error(), err);
fprintf(stderr, "Error encrypting message: %s\n", err);
free(err);
return nullptr;
}
return encData;
}
unsigned char* Rsa::ossl_decryptWithPbKey (const unsigned char *encData, int dataSize, int &newSize) {
unsigned char *data = new unsigned char[RSA_size(keypair)];
newSize = RSA_public_decrypt(RSA_size(keypair), encData, data, keypair, RSA_PKCS1_PADDING);
if (newSize == -1) {
char* err = (char*) malloc(130);
ERR_load_crypto_strings();
ERR_error_string(ERR_get_error(), err);
fprintf(stderr, "Error encrypting message: %s\n", err);
free(err);
return nullptr;
}
return data;
} |
Partager