Solved

Simple code to encrypt a string? VB ASP.NET

Posted on 2011-02-27
4
758 Views
Last Modified: 2012-05-11
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
Comment
Question by:arthurh88
4 Comments
 
LVL 2

Expert Comment

by:jondow
Comment Utility
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
 
LVL 29

Expert Comment

by:Paul Jackson
Comment Utility
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 500 total points
Comment Utility
<< 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
 

Author Comment

by:arthurh88
Comment Utility
right a one way hash, thats it.  thank you for clarifying that.  
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now