Could you try to write a minimal working example in a separate project and 
share the code if you still have any issues? Try to write that 
encryption/decryption routines yourself line by line instead of copy&paste 
any examples.

The idea is simple: you read data source, you put data through the filter 
(which does the encryption or decryption) and put the result to the sink. 
So you should setup a source: read file in buffer and use StringSource or 
VectorSource or use FileSource. Then you should prepare an encryption 
filter (StreamTransformationFilter) with appropriate options (you could 
learn it from example code). Then you put the data into the Sink.

Remember to use same key & iv for decryption. Also binary/text mode is 
important when reading files. Also remember to use same mode (CBC, ECB, 
etc.) for both encryption/decryption algorithm. Use authenticated 
encryption to catch message checksum errors.

Try to experiment with pipelining, e.g. calculating messag digest and 
printing it in hex. When you get the strong feeling what works and what 
isn't you could easily use any encryption/decryption algorithm in Cryptopp. 
Just take some time to read wiki and experiment with library primitives. 
And good luck with that!

вторник, 29 ноября 2022 г. в 23:01:33 UTC+7, 

> Not sure what you mean by format, i just use something like "myFileStream 
> << cipher", and then read it back again. Do you mean that the txt file 
> should be utf-8 or something like that? What would be the right way to 
> write the ciphered string to the txt file and read it afterwards? Thanks a 
> lot for answering btw.
> On Tuesday, November 29, 2022 at 4:15:37 PM UTC+2 
> wrote:
>> I think I have an idea of ​​what is happening to you, what happens that 
>> you must decrypt in the same format that you encrypted, since that happened 
>> to me at some point, you must also see the format in how you return the txt 
>> file, or the text of txt if it is the same format that is needed to decrypt 
>> it. Greetings.
>> El lunes, 28 de noviembre de 2022 a las 14:30:04 UTC-5, 
>> escribió:
>>> Ok so based on the example from this link   (
>>>,    i have 
>>> tried encrypting a "plain" string into a "cipher" string and writing that 
>>> "cipher" string to a .txt file in one program, and in another program 
>>> afterwards reading that same .txt file into a string and decrypting it. But 
>>> when i cout that "recovered" string, it is just  random characters and not 
>>> my original "plain" string. I think the problem starts when i attempt to 
>>> get the "cipher" string in the .txt file, but not sure. Any help is greatly 
>>> appreciated. Thanks in advance.

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 view this discussion on the web visit

Reply via email to