0

I have C# code that is writing to a text file where the password inputted by the user gets encrypted through AES using EasyEncryption. I have both key and iv set to 128bit and encryption works fine. However, when I try to decrypt the password, I keep getting the incomplete block message.

        //PASSWORD IS BEING ENCRYPTED BEFORE SAVING TO TEXT FILE
        var keyValue = "/A?D(G+KbPeShVkY";
        var ivValue = "*G-KaPdSgVkYp3s5";
        var pEncryption = EasyEncryption.AES.Encrypt(PASSWORD, keyValue, ivValue);
        Console.WriteLine("\nPassword encrypted= " + pEncryption);
        file.WriteLine("password=" + pEncryption);

This is the decryption part that gives me the block error

        //PASSWORD DECRYPTION
        var keyValue = "/A?D(G+KbPeShVkY";
        var ivValue = "*G-KaPdSgVkYp3s5";
        var dcryPassword = EasyEncryption.AES.Decrypt(data["password"],keyValue, ivValue);

2 Answers2

0

i have faced similar issue, and resolved by observingthe input text for decryt() method some time it is malformed.

you can also check the same.

0

Okay, I finally figured out a solution. I was attempting to decrypt the password straight from a notepad file which reads by default UTF8. I read the encrypted password using a string called rpass (read password) and then used rpass to be decrypted. Works as it should now.

//Need to read from text UTF8 before trying to decrypt, == is padding
            string rpass = data["password"] + "==";
            Console.WriteLine(rpass);
            string dpass = Decrypt(rpass);
            Console.WriteLine("decryption= " + dpass);