• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1097
  • Last Modified:

asp.net encryption and decryption

Do you know any good asp.net codes for encryption and decryption in c#?
The one we used has some issues.

like The input data is not a complete block.
Exception Details: System.Security.Cryptography.CryptographicException: The input data is not a complete block.

We do not know why and do not have time to fix it. It will be quicker for us to just replace a new and working one
  • 2
1 Solution
ITsolutionWizardAuthor Commented:
-first one is not working.  And just FYI, that is the one I used.
-second one does not work when you put more than 6 characters.
Lokesh B RDeveloperCommented:

You can use the following methods

 private string EncryptData(string password)
            string strmsg = string.Empty;
            byte[] encode = new byte[password.Length];
            encode = System.Text.Encoding.UTF8.GetBytes(password);
            strmsg = Convert.ToBase64String(encode);
            return strmsg;

Open in new window

private string DecryptData(string encryptpwd)
            string decryptpwd = string.Empty;
            System.Text.UTF8Encoding encodepwd = new System.Text.UTF8Encoding();
            System.Text.Decoder Decode = encodepwd.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
            int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            decryptpwd = new String(decoded_char);
            return decryptpwd;

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now