Neozaru
Neozaru

Reputation: 1130

Decrypting data with Rsa Private Key/Function

I'm just trying to encode/decode data (decode, firstly) with RSA. I don't care of the type of data (string, bytes, or other lolcat-encoded data), I just looking a very simple function doing the job (cryptographic operations) and I can do the rest.

Here is what I tried :

CryptoPP::InvertibleRSAFunction rsa;

rsa.SetModulus( n_factor );
rsa.SetPrivateExponent(d_private_exponent);

rsa.SetPrime1( rsa_params.at(p1) );
rsa.SetPrime2( rsa_params.at(p2) );

// All above inputs are correct. I don't have public exponent, but it's works in other languages (I comprared all inputs/outputs)

bool key_ok = rsa.Validate(CryptoPP::NullRNG(), 15);
/* Returns false, but doesn't tell me why :/ */

CryptoPP::Integer to_decode( my_data, size_of_my_data );
res = rsa.CalculateInverse(rg,to_decode); 

This returns:

EXCEPTION : what():  CryptoMaterial: this object contains invalid values

Returned error code corresponds to "INVALID_DATA_FORMAT", which probably doesn't mean a key problem, but an input problem.

If anyone has some experience with this library, or detects a "noob" mistake (I've my mind in code since 4 hours, so it is possible), any help would be appreciated.

Upvotes: 1

Views: 894

Answers (1)

Neozaru
Neozaru

Reputation: 1130

Easier than I thought :

CryptoPP::Integer dec_data = a_exp_b_mod_c( enc_data, d_private_exponent, n_modulus );

So 'd' and 'n' were enought. I really don't understand why it didn't work with crypto features.

Upvotes: 1

Related Questions