SoFunction
Updated on 2025-03-06

Several methods of implementing encryption in C#

Code encryption

//ASCII code encryption        private static string ACSIIPWd(string rpwd)
        {
            string Ret;
            byte[] array = (rpwd);
            byte[] byteArray = new byte[];

            for (int i = 0; i < ; i++)
            {
                int asciicode = (int)(array[i]);
                asciicode = asciicode + 1;
                byteArray[i] = (byte)asciicode;
            }
             asciiEncoding = new ();
            string strCharacter = (byteArray);
            Ret = strCharacter;
            return Ret;
        }

2.MD5 encryption

//MD5 encryption        private static string MD5PWd(string rpwd)
        {
            string Ret;

            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] palindata = (rpwd);//Convert the string to be encrypted into a byte array            byte[] encryptdata = (palindata);//Encrypt the string and convert it into a character array            Ret = Convert.ToBase64String(encryptdata);
            return Ret;
        }

encryption

//RSA encryption        private static string RSAPWD1(string myKeyContainerName)
        {
            string ret = "";         
            CspParameters cp = new CspParameters();
             = myKeyContainerName;
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);
           
            ret = (true);
            ("Key is : \n" + (true));
            return ret;

        }

encryption

//DES encryption        private static string DESPWD(string ciphertext)
        {
            string desPWD = ""; 
            byte[] buffer;
            DESCryptoServiceProvider DesCSP = new DESCryptoServiceProvider();

            MemoryStream ms = new MemoryStream();// Create a memory stream first            CryptoStream cryStream = new CryptoStream(ms, (), );//Connect memory stream to encrypted conversion stream            StreamWriter sw = new StreamWriter(cryStream);
            (ciphertext);//Write the string to be encrypted into the encrypted conversion stream            ();
            ();
            buffer = ();//Convert the encrypted stream into a byte array            desPWD = Convert.ToBase64String(buffer);//Convert the encrypted byte array to a string
            return desPWD;
        }

This is all about this article about C# implementation of encryption. I hope it will be helpful to everyone's learning and I hope everyone will support me more.