nagilum / cryptocsharp

C# lib to encrypt and decrypt data with symmetric/asymmetric algorithms
MIT License
22 stars 10 forks source link

Not working? #1

Closed gn4711 closed 4 years ago

gn4711 commented 5 years ago

Hi, Im trying the code. Encrypting a PDF symetric and decrypting it again, and the result is different. How is this possible? Also, for the final .where in the return statement I had to add using System.Linq; to get it compiled.

     var pwd = "loremipsumdolorsetamet";
     var bytesIn = File.ReadAllBytes(dataFile);
     var bytesOut = Cryptography.Symmetric.Encrypt(bytesIn, pwd);
     File.WriteAllBytes("out1.enc", bytesOut);
     var newbytesIn = Cryptography.Symmetric.Decrypt(bytesOut, pwd);
     File.WriteAllBytes("out2.pdf", newbytesIn);
nagilum commented 4 years ago

Sorry for the late reply, and I'm assuming you got some other code to work, but I wanted to address the issue anyways.

The error occurred because I was stripping out the zero-bytes from the decrypted data. That was wrong. I've changed the code to filter out the trailing zero-bytes. That did it. Tested with a 13mb PDF now and the decrypted version is equal to the normal version.