0

Hi, I am using windows application in c#. In one form their is two Richtextbox i want to save these richtextbox value as encrypted format in sql server and again displayed by decrypting it.

Can anybody help me...

Thanks in advance

Edited by bhagawatshinde: n/a

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by bhagawatshinde
0

Hi I am managed to solve this problem by using Below algorithm but still not decrypted at high level means that suppose maths answer about 1 page containing math type equations it will not properly decrypted.

public static string Encrypt256(string Data, string Password)
        {
            byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(Data);


            PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,


                new byte[] { 0x00, 0x01, 0x02, 0x1C, 0x1D, 0x1E, 0x03, 0x04, 0x05, 0x0F, 0x20, 0x21, 0xAD, 0xAF, 0xA4 });
            MemoryStream ms = new MemoryStream();

            Rijndael alg = Rijndael.Create();
            alg.Key = pdb.GetBytes(32);

            alg.IV = pdb.GetBytes(16);
            CryptoStream cs = new CryptoStream(ms, alg.CreateEncryptor(), CryptoStreamMode.Write);

            cs.Write(clearBytes, 0, clearBytes.Length);
            cs.Close();
            byte[] encryptedData = ms.ToArray();
            return Convert.ToBase64String(encryptedData);


        }

        public static string Decrypt256(string Data, string Password)
        {
            byte[] clearBytes = Convert.FromBase64String(Data);


            PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,


                new byte[] { 0x00, 0x01, 0x02, 0x1C, 0x1D, 0x1E, 0x03, 0x04, 0x05, 0x0F, 0x20, 0x21, 0xAD, 0xAF, 0xA4 });
            MemoryStream ms = new MemoryStream();

            Rijndael alg = Rijndael.Create();
            alg.Key = pdb.GetBytes(32);

            alg.IV = pdb.GetBytes(16);
            CryptoStream cs = new CryptoStream(ms, alg.CreateDecryptor(), CryptoStreamMode.Write);

            cs.Write(clearBytes, 0, clearBytes.Length);
            cs.Close();
            byte[] decryptedData = ms.ToArray();
            return System.Text.Encoding.Unicode.GetString(decryptedData);
    
        }

Edited by bhagawatshinde: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.