Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Very simple Encryption/Decryption code using VB

Total Hit ( 5144)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


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

'Encrypt text
Private Function EncryptText(strText As String, ByVal strPwd As String)
  Dim i As Integer, c As Integer
  Dim strBuff As String

  'Encrypt 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

'Decrypt text encrypted with EncryptText
Private Function DecryptText(strText As String, ByVal strPwd As String)
  Dim i As Integer, c As Integer
  Dim strBuff As String

  'Decrypt 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 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.