Encryption and Decryption Submitted By: Yasir Attiq Butt, eWorx InternationalPosted On: 3/11/2005 Overall Rating: 1 (1 ratings, 1 comments) Description:Before I found a small code piece to easily secure data in .Net; I've always felt a little disturbed when sending my query strings and information like user names, passwords etc. to other pages in ASP.Net without Encrypting/Decrypting my UserName/Passwords in databases. The code is written below. Simple copy and paste it to any class in Visual basic project form and start using it. Sub DoEncryptionDecryption dim objHash as new Hashing dim strEncryptedText as string=““ strEncryptedText = objHash.encrypt(“TextToEncrypt“) Messagebox.show(strEncryptedText) dim strDecryptedText as string strDecryptedText = objHash.Decrypt (strEncryptedText) Messagebox.show(strDecryptedText ) End Sub Hashing Class is written below in the code example Regards Yasir Attiq Butt Imports System.Security.Cryptography Imports System.Text Public Class Hashing'******* Encrypt the Data *******Public Function GetEncryptedData(ByVal Data As String) As StringDim shaM As New SHA1ManagedConvert.ToBase64String(shaM.ComputeHash(Encoding.ASCII.GetBytes(Data)))Dim eNC_data() As Byte = ASCIIEncoding.ASCII.GetBytes(Data)Dim eNC_str As String = Convert.ToBase64String(eNC_data)GetEncryptedData = eNC_strEnd Function'******* Decrypt the Data *******Public Function GetDecryptedData(ByVal Data As String) As StringDim dEC_data() As Byte = Convert.FromBase64String(Data)Dim dEC_Str As String = ASCIIEncoding.ASCII.GetString(dEC_data)GetDecryptedData = dEC_StrEnd FunctionEnd Class

评论