Wednesday, 4 April 2018

Simple Data Encryption And Decryption in C# using ASCIIEncoding

/////////////


    string mm = "h3dhu12";
    string pp = EnryptString(mm);
    string qq = DecryptString(pp);
    public string DecryptString(string encrStr)
    {
        byte[] b;
        string decrypted;
        try
        {
            b = Convert.FromBase64String(encrStr);
            decrypted = System.Text.ASCIIEncoding.ASCII.GetString(b);
        }
        catch (FormatException fe)
        {
            decrypted = "";
        }
        return decrypted;
    }

    public string EnryptString(string strEnc)
    {
        byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(strEnc);
        string encrypted = Convert.ToBase64String(b);
        return encrypted;
    }


No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...