Friday, 18 July 2014

Namespace for Encryption and Decryption in c#



Imports System.Security.Cryptography

C# Source Code:



// Method for encrypt the string value using SHA notation
private string Encrypt(string Data)
{
 SHA1Managed shaM = new SHA1Managed(); Convert.ToBase64String(shaM.ComputeHash(Encoding.ASCII.GetBytes(Data))); byte[] eNC_data = ASCIIEncoding.ASCII.GetBytes(Data);
 string eNC_str = Convert.ToBase64String(eNC_data);
 return eNC_str;
}


// Method for decrypt the encrypted value using SHA notation
private string Decrypt (string Data)
{
 byte[] dEC_data = Convert.FromBase64String(Data);
 string dEC_Str = ASCIIEncoding.ASCII.GetString(dEC_data);
 return dEC_Str;
}



How to use:

Using these function you will get Encrypted and Decrypted form of data.



string enc_value = Encrypt (“Test”);
string dcrp_value = Decrypt (enc_value);













No comments:

Post a Comment