Hi all!

I have an ordinary, but easy, problem. Need to save public key into string 
and load from this string.
Saving and loading are successed in the test code, but when I try to create 
decryptor from mey new public key (which are loaded wrom string) - i had an 
exception "Missing required parameter Primel1".
Wich parameter i need to add? What is the problem with this code?

In debug I see correct value inside all strings...


>    1. //for generate IV and Key
>    2. #include "D:/Crypto++/cryptopp820/osrng.h"
>    3. using CryptoPP::AutoSeededRandomPool;
>    4.  
>    5. #include <string>
>    6. using std::string;
>    7.  
>    8. //for exceptions
>    9. #include "D:/Crypto++/cryptopp820/cryptlib.h"
>    10. using CryptoPP::Exception;
>    11.  
>    12. //for hex viewing
>    13. #include "D:/Crypto++/cryptopp820/hex.h"
>    14. using CryptoPP::HexDecoder;
>    15. using CryptoPP::HexEncoder;
>    16.  
>    17. //converter input into cipher
>    18. #include "D:/Crypto++/cryptopp820/filters.h"
>    19. using CryptoPP::StringSink;
>    20. using CryptoPP::StreamTransformation;
>    21. using CryptoPP::StreamTransformationFilter;
>    22.  
>    23. //add AES
>    24. #include "D:/Crypto++/cryptopp820/aes.h"
>    25. using CryptoPP::AES;
>    26.  
>    27. #include "D:/Crypto++/cryptopp820/modes.h"
>    28. using CryptoPP::CBC_Mode;
>    29.  
>    30. #include "D:/Crypto++/cryptopp820/md5.h"
>    31. using CryptoPP::MD5;
>    32.  
>    33. #include "D:/Crypto++/cryptopp820/blowfish.h"
>    34. #include "D:/Crypto++/cryptopp820/rsa.h"
>    35. #include "D:/Crypto++/cryptopp820/eccrypto.h"
>    36. #include "D:/Crypto++/cryptopp820/base64.h"
>    37. using CryptoPP::Blowfish;
>    38. #include <iostream>
>    39. using namespace std;
>    40. using namespace CryptoPP;
>    41.  
>    42.  
>    43. int main()
>    44. {
>    45.     //create public+private keys
>    46.     //encrypt some text
>    47.     //pack public key into the string or vector char
>    48.     //unpack public key and decrypt text
>    49.  
>    50.  
>    51.     std::string testText = "Text text";
>    52.     std::string encryptText, decryptText, for_save_key, packedKey, 
>    unpackedKey;
>    53.  
>    54.     AutoSeededRandomPool rng(true);
>    55.     InvertibleRSAFunction params;
>    56.     params.GenerateRandomWithKeySize(rng, 3072);
>    57.  
>    58.     RSA::PrivateKey privateKey(params);
>    59.     RSA::PublicKey publicKey(params);
>    60.  
>    61.     RSAES_OAEP_SHA_Encryptor encryptor(publicKey);
>    62.     StringSource(testText, true, new PK_EncryptorFilter(rng, 
>    encryptor, new StringSink(encryptText)));
>    63.  
>    64.     //try to pack public key
>    65.     RSA::PublicKey newPublicKey;
>    66.     try
>    67.     {
>    68.         StringSink tmp_key(for_save_key);
>    69.         publicKey.Save(tmp_key);
>    70.         newPublicKey.Load(CryptoPP::StringStore((const byte*)
>    for_save_key.data(), for_save_key.size()).Ref());
>    71.     }
>    72.     catch (const BERDecodeErr& ex)
>    73.     {
>    74.         cerr << ex.what() << endl;
>    75.     }
>    76.  
>    77.     try
>    78.     {
>    79.         RSAES_OAEP_SHA_Decryptor decryptor(newPublicKey);
>    80.         StringSource(encryptText, true, new PK_DecryptorFilter(rng, 
>    decryptor, new StringSink(decryptText)));
>    81.     }
>    82.     catch (InvalidArgument& ex)
>    83.     {
>    84.         cerr << ex.what() << endl;
>    85.     }  
>    86.  
>    87.     std::cout << "Decrypt text: " << decryptText << endl;
>    88.  
>    89.     system("pause");
>    90.     return 0;
>    91. }
>    
>

-- 
You received this message because you are subscribed to "Crypto++ Users". More 
information about Crypto++ and this group is available at 
http://www.cryptopp.com and 
http://groups.google.com/forum/#!forum/cryptopp-users.
--- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/03e419a1-bca8-4403-8bf2-97eedc5c1c22%40googlegroups.com.

Reply via email to