Solved

Simple code to encrypt a string? VB ASP.NET

Posted on 2011-02-27
4
759 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
ID: 34993161
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
ID: 34993214
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 500 total points
ID: 34993306
<< 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
ID: 34993433
right a one way hash, thats it.  thank you for clarifying that.  
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

778 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