Re: PK_DecryptorFilter Returns empty string
Jeffrey Walton <[email protected]> Tue, 14 Jun 2022 19:47:18 -0700 (PDT)
| Newsgroups | gmane.comp.encryption.cryptopp |
|---|---|
| Message-ID | <[email protected]> |
On Wednesday, June 8, 2022 at 10:10:41 PM UTC-4 [email protected] wrote: > Hi there > i have two functions encrypt and decrypt as follows > > *ENCRYPT()* > ECIES<ECP>::Decryptor d0(prng, ASN1::secp256r1()); > PrintPrivateKey(d0.GetKey()); > > ECIES<ECP>::Encryptor e0(d0); > PrintPublicKey(e0.GetKey()); > SavePrivateKey(d0.GetPrivateKey()); > SavePublicKey(e0.GetPublicKey()); > > ifstream infile; > ofstream outfile; > string sen,sen1,line,enc; > sen.clear(); > line.clear(); > enc.clear(); > infile.open("Me/text.txt"); > if(infile.is_open()){ > while(!infile.eof()){ > getline(infile,line); > sen1 = sen1 + line; > } > } > StringSource ss1(sen,true,new PK_EncryptorFilter(prng,e0,new > StringSink(enc))); > cout<<"Encrypted:"<<endl<<enc<<endl; > infile.close(); > string encoded; > StringSource ss3(enc, true, new HexEncoder(new StringSink(encoded))); > outfile.open("Me/e1nc_text.txt"); > outfile<<encoded; > outfile.close(); > cout<<"Encoded: "<< encoded<<endl; > > > *--------------------------------------------------------------------------------------------------------* > In the above function a file is opened and all the content is first > ENCRYPTED using ECIES > and the ENCODED WITH HEXENCODER and Saved in an another file. > > > > ------------------------------------------------------------------------------------------------------------------------------------------------ > *DECRYPT()* > > ECIES<ECP>::Decryptor d1; > ECIES<ECP>::Decryptor d0(prng, ASN1::secp256r1()); > LoadPrivateKey(d1.AccessPrivateKey()); > d1.GetPrivateKey().ThrowIfInvalid(prng, 3); > > ECIES<ECP>::Encryptor e1; > LoadPublicKey(e1.AccessPublicKey()); > e1.GetPublicKey(). ThrowIfInvalid(prng, 3); > > PrintPrivateKey(d1.GetKey()); > PrintPublicKey(e1.GetKey()); > > ifstream file; > string sen,line,dec,decoded; > sen.clear(); > line.clear(); > file.open("Me/e1nc_text.txt"); > if(file.is_open()){ > while(!file.eof()){ > getline(file,line); > sen = sen + line; > } > } > StringSource ss7 (sen,true, new HexDecoder(new StringSink(decoded))); > cout<<"Decoded"<<endl<<decoded; > StringSource ss8 (decoded,true,new PK_DecryptorFilter(prng,d1,new > StringSink(dec))); > cout<<endl<<"Decrypted:"<<endl; > cout<<dec; > ofstream outfile("Me/decrypt.txt"); > outfile<<dec; > > -------------------------------------------------------------------------------------------------------------------------------------------------- > The encrypted and encoded file is extracted and first decoded after that > at decryption part > the string variable dec is the one in which the decrypted string should be > stored but when out putted it shows empty string > > The output of the above is the following:[image: Screenshot from > 2022-06-09 07-37-06.png] > THE ENCRYPTED and THE DECODED OUTPUTS ARE the same thus its not an invalid > cipher text yet At the last line the *Decrypted : *as we can see is > empty. > Please provide a self contained sample that I can compile and run. Also, you should consider using a FileSource/FileSink instead of file streams. Jeff -- 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/af2e6ee8-9b9d-4c88-8005-ab3007c96a52n%40googlegroups.com.
Screenshot from 2022-06-09 07-37-06.png
(image/png, 229.2 KB) - not displayed