Solved

Simple code to encrypt a string? VB ASP.NET

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

713 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