Heluuu,

I've been trying to set up an (offline) authentication system. The idea is 
that the source should generate a license based on various things and then 
encrypt that license. The recipient should receive this encrypted file 
along with the key to decrypt it, and these two are then used to validate 
the installation.

Unfortunately, I've been having some troubles with my encryption/decryption 
process. 
Since I want the user to have his/her own key for decryption purposes, I 
need an asymmetric cipher, and RSA (which was originally supposed to be 
ordered alphabetically) seems like a suitable candidate. 
The message to be encrypted is 385 characters long, and thus I am using a 
modulus of 4096. Other parameters I am unaware of, as the keys are 
generated with the GenerateRandomWithKeySize function.
The keys are stored (DER encoded) as files, and loaded before use. 

When running the program, I get the error "RSA/OAEP-MGF1(SHA-1): ciphertext 
length of 72 doesn't match the required length of 512 for this key".
While not cryptic (harhar) in itself, I was under the impression that 
encrypting with RSAES_OAEP_SHA_Encryptor would always pad the message to 
match the keysize.

Thus, I would kindly request help with this issue.

The functions for encrypting and decrypting are as follows:


//Encryption part.
std::string
KeyCrypto::EncryptRSA(std::string& plaintext) {

        std::string cipher;
        RSA::PrivateKey key;
        AutoSeededRandomPool srng;
//GEN_KEY is the filesource for the private key. ENCODING is a string flag 
that sets the key encoding algorithm (defaults to DER/BER)
        LoadPrivateKey(GEN_KEY, key, ENCODING);


        RSAES_OAEP_SHA_Encryptor encryptor(key);

        StringSource ss(plaintext, true, new PK_EncryptorFilter(srng, 
encryptor, new StringSink(cipher)));

        return cipher;
}

std::string
KeyCrypto::DecryptRSA(std::string& cipher) {

        std::string plaintext;
        RSA::PrivateKey key;
        AutoSeededRandomPool srng;
//KEY_FILE is the filesource for the public key, ENCODING is a string flag 
that sets the encoding algorithm (defaults to DER/BER)
        LoadPublicKey(KEY_FILE, key, ENCODING);

        RSAES_OAEP_SHA_Decryptor decryptor(key);

        StringSource ss(cipher, true, new PK_DecryptorFilter(srng, 
decryptor, new StringSink(plaintext)));            
                                                                                
                                      

        return 
plaintext;                                                                      
                       

}                                                                               
                                      


...
...

"RSA/OAEP-MGF1(SHA-1): ciphertext length of 72 doesn't match the required 
length of 512 for this key"
Apart from these snippets, I have also tried using other functions 
(encryptor.Encrypt(...)) with other sources and sinks (byteQueues and 
SecByteBlocks).

Thank you for any help



-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to