C# and VB.Net Encryption

Hi. These following code will show you the encryption and decryption of your data.


public static string EncryptString(string strString)
Byte[] _bitEncrypt;
string EnCrypted;

_bitEncrypt = ASCIIEncoding.ASCII.GetBytes(strString);
EnCrypted = Convert.ToBase64String(_bitEncrypt);
return EnCrypted;
public static string DecryptString(string strString)
Byte[] _bitDecrypt;
string Decrypted;

_bitDecrypt = Convert.FromBase64String(strString);
Decrypted = ASCIIEncoding.ASCII.GetString(_bitDecrypt);
return Decrypted;


Public Function EncryptQueryString(ByVal queryString As String) As String
Dim _bitEncrypt As Byte()
_bitEncrypt = ASCIIEncoding.ASCII.GetBytes(queryString)
Dim encryptedQueryString As String = Convert.ToBase64String(_bitEncrypt)
Return encryptedQueryString
End Function

Public Function DecryptQueryString(ByVal queryString As String) As String
Dim _bitDecrypt As Byte()
_bitDecrypt = Convert.FromBase64String(queryString)
Dim decryptedQueryString = ASCIIEncoding.ASCII.GetString(_bitDecrypt)
Return decryptedQueryString
End Function

I hope this one will help many.

Reference: http://codeincsharp.blogspot.com/2008/08/encrypt-and-decrypt-in-c.html


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: