|
|
|
This code will show you how to encrypt/decrypt a string.
Copy/Paste the following code in your VB form and press F5 to run. |
Click here to copy the following block | Const ENCRYPTION_KEY = "MySecreteKey123"
Private Sub Form_Load() Dim txt As String, enctxt As String txt = "Your password is : asd$223" enctxt = EncryptText(txt, ENCRYPTION_KEY) MsgBox "Encrypted text >> " & enctxt MsgBox "Decrypted text >> " & DecryptText(enctxt, ENCRYPTION_KEY) End Sub
Private Function EncryptText(strText As String, ByVal strPwd As String) Dim i As Integer, c As Integer Dim strBuff As String
If Len(strPwd) Then For i = 1 To Len(strText) c = Asc(Mid$(strText, i, 1)) c = c + Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1)) strBuff = strBuff & Chr$(c And &HFF) Next i Else strBuff = strText End If EncryptText = strBuff End Function
Private Function DecryptText(strText As String, ByVal strPwd As String) Dim i As Integer, c As Integer Dim strBuff As String
If Len(strPwd) Then For i = 1 To Len(strText) c = Asc(Mid$(strText, i, 1)) c = c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1)) strBuff = strBuff & Chr$(c And &HFF) Next i Else strBuff = strText End If DecryptText = strBuff End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|