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
LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
0
Lokesh B RDeveloperCommented:
Hi,

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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.