Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 770
  • Last Modified:

Simple code to encrypt a string? VB ASP.NET

All I need is a simple piece of VB code for ASP.NET that will encrypt a string and return a bunch of encrypted characters.

Please use for the code:
 Dim Input as string = "My String"
 Dim SID As String

SID should be the resulting string once Input is encrypted.  I dont need decryption, just encryption so that it will always return the same SID when you encrypt the same Input string.  

I hope this makes sense.  Thank you!
0
arthurh88
Asked:
arthurh88
1 Solution
 
jondowCommented:
Try this for a simple and non complex method:

Public Function SimpleCrypt( _
       ByVal Text As String) As String
  ' Encrypts/decrypts the passed string using
  ' a simple ASCII value-swapping algorithm
  Dim strTempChar As String, i As Integer
  For i = 1 To Len(Text)
    If Asc(Mid$(Text, i, 1)) < 128 Then
      strTempChar = _
CType(Asc(Mid$(Text, i, 1)) + 128, String)
    ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
      strTempChar = _
CType(Asc(Mid$(Text, i, 1)) - 128, String)
    End If
    Mid$(Text, i, 1) = _
        Chr(CType(strTempChar, Integer))
  Next i
  Return Text
End Function

Source:
http://www.developer.com/net/vb/article.php/3292781/VB-NET-Tip-Encryption-in-Just-Twelve-Lines-of-Code.htm
0
 
Paul JacksonCommented:
0
 
nffvrxqgrcfqvvcCommented:
<< SID should be the resulting string once Input is encrypted >>

You don't want encryption. What your looking for is whats called a one way hash such as MD5 or SHA1.

System.Security.Cryptography
http://msdn.microsoft.com/en-us/library/9eat8fht.aspx

MSDN MD5 hash example- The only thing I would change is to use BitConverter.ToString() instead of X2
http://msdn.microsoft.com/en-us/library/system.security.cryptography.md5cryptoserviceprovider.aspx
0
 
arthurh88Author Commented:
right a one way hash, thats it.  thank you for clarifying that.  
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now