U are my hero! How I could be so inattentive?! All works properly. Thanks a lot!
воскресенье, 2 июня 2019 г., 13:11:29 UTC+3 пользователь Jeffrey Walton написал: > > On Sun, Jun 2, 2019 at 5:53 AM Наталья <[email protected] <javascript:>> > wrote: > > > > 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... > > > >> //for generate IV and Key > >> #include "D:/Crypto++/cryptopp820/osrng.h" > >> using CryptoPP::AutoSeededRandomPool; > >> > >> #include <string> > >> using std::string; > >> > >> //for exceptions > >> #include "D:/Crypto++/cryptopp820/cryptlib.h" > >> using CryptoPP::Exception; > >> > >> //for hex viewing > >> #include "D:/Crypto++/cryptopp820/hex.h" > >> using CryptoPP::HexDecoder; > >> using CryptoPP::HexEncoder; > >> > >> //converter input into cipher > >> #include "D:/Crypto++/cryptopp820/filters.h" > >> using CryptoPP::StringSink; > >> using CryptoPP::StreamTransformation; > >> using CryptoPP::StreamTransformationFilter; > >> > >> //add AES > >> #include "D:/Crypto++/cryptopp820/aes.h" > >> using CryptoPP::AES; > >> > >> #include "D:/Crypto++/cryptopp820/modes.h" > >> using CryptoPP::CBC_Mode; > >> > >> #include "D:/Crypto++/cryptopp820/md5.h" > >> using CryptoPP::MD5; > >> > >> #include "D:/Crypto++/cryptopp820/blowfish.h" > >> #include "D:/Crypto++/cryptopp820/rsa.h" > >> #include "D:/Crypto++/cryptopp820/eccrypto.h" > >> #include "D:/Crypto++/cryptopp820/base64.h" > >> using CryptoPP::Blowfish; > >> #include <iostream> > >> using namespace std; > >> using namespace CryptoPP; > >> > >> > >> int main() > >> { > >> //create public+private keys > >> //encrypt some text > >> //pack public key into the string or vector char > >> //unpack public key and decrypt text > >> > >> > >> std::string testText = "Text text"; > >> std::string encryptText, decryptText, for_save_key, packedKey, > unpackedKey; > >> > >> AutoSeededRandomPool rng(true); > >> InvertibleRSAFunction params; > >> params.GenerateRandomWithKeySize(rng, 3072); > >> > >> RSA::PrivateKey privateKey(params); > >> RSA::PublicKey publicKey(params); > >> > >> RSAES_OAEP_SHA_Encryptor encryptor(publicKey); > >> StringSource(testText, true, new PK_EncryptorFilter(rng, encryptor, > new StringSink(encryptText))); > >> > >> //try to pack public key > >> RSA::PublicKey newPublicKey; > >> try > >> { > >> StringSink tmp_key(for_save_key); > >> publicKey.Save(tmp_key); > >> newPublicKey.Load(CryptoPP::StringStore((const > byte*)for_save_key.data(), for_save_key.size()).Ref()); > >> } > >> catch (const BERDecodeErr& ex) > >> { > >> cerr << ex.what() << endl; > >> } > >> > >> try > >> { > >> RSAES_OAEP_SHA_Decryptor decryptor(newPublicKey); > >> StringSource(encryptText, true, new PK_DecryptorFilter(rng, > decryptor, new StringSink(decryptText))); > >> } > >> catch (InvalidArgument& ex) > >> { > >> cerr << ex.what() << endl; > >> } > >> > >> std::cout << "Decrypt text: " << decryptText << endl; > >> > >> system("pause"); > >> return 0; > >> } > > The decryptor should use the private key, not the public key. This is > incorrect: > > RSAES_OAEP_SHA_Decryptor decryptor(newPublicKey); > > Jeff > -- 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/3bf2ac3d-2874-4914-a95d-3f7be0ea4173%40googlegroups.com.
