正文

加密和解密(vb.net)2006-06-25 07:39:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/iamben250/16168.html

分享到:

  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

阅读(3532) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册