sdrapkin / SecurityDriven.Inferno

:white_check_mark: .NET crypto done right. Professionally audited.
https://SecurityDriven.NET/inferno/
Other
568 stars 50 forks source link

SuiteB Encryption/Decription of data does not match #41

Closed ItSkary closed 2 years ago

ItSkary commented 2 years ago

Greetings, probably i mistakenly used some API but i have followed example of code usage, and try to test latest version of the library (version 1.6.4, the latest on nuget) to crypt/decrypt some data.

Here the dummy example i have write to test how to use library :

            byte[] key = new byte[] {97,98,99};
            string text = "text";

            var encr = SuiteB.Encrypt(key, text.ToBytes().AsArraySegment()).ToB64();
            var decr = SuiteB.Decrypt(key, encr.FromB64().AsArraySegment());

image

As you can see decryption seems to attach empty character after each character of the plain text : 'text' -> 't\0e\0x\0t\0'

Here how i have installed the library : image

Have i missused some configuration/API?

sdrapkin commented 2 years ago
byte[] key = new byte[] { 97, 98, 99 };
string text = "text";

var encr = SuiteB.Encrypt(key, text.ToBytes().AsArraySegment()).ToB64();
var decr = SuiteB.Decrypt(key, encr.FromB64().AsArraySegment()).FromBytes();

Console.WriteLine(decr);
ItSkary commented 2 years ago

Ah thank a lot. Tomorrow I will test it, but I have no doubt that my misunderstanding (a missing FromBytes) is the cause of the issue. Thanks again for the clarification and swift answer

ItSkary commented 2 years ago

I can confirm adding FromBytes() solve the issues