Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Simple code to encrypt a string? VB ASP.NET

Posted on 2011-02-27
4
760 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 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