blow fish.
use encryption
http://www.example-code.co
Main Topics
Browse All TopicsHi,
Is there a simple method using perhaps a key to hash and unhash a string value using the ,net framework ONLY?
my app is running on Framework 2 and up
I would like to Hash example "Hello World", then be able to pass the "Hashed" value into a function to dehash it back to "Hello World"
thanks allot
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
blow fish.
use encryption
http://www.example-code.co
Here is a nice simple soloution for you and I have tested it for you .....
First simply create the class
Imports System.Security.Cryptograp
Imports System.IO
Public Class Encryptor
'Supported .Net intrinsic SymmetricAlgorithm classes.
Public Enum Providers
[DES]
[RC2]
[Rijndael]
End Enum
Private _CryptoService As SymmetricAlgorithm
'Constructor for using an intrinsic .Net SymmetricAlgorithm class.
Public Sub New(ByVal NetSelected As Providers)
Select Case NetSelected
Case Providers.DES
_CryptoService = New DESCryptoServiceProvider
Case Providers.RC2
_CryptoService = New RC2CryptoServiceProvider
Case Providers.Rijndael
_CryptoService = New RijndaelManaged
End Select
End Sub
'Constructor for using a customized SymmetricAlgorithm class.
Public Sub New(ByVal ServiceProvider As SymmetricAlgorithm)
_CryptoService = ServiceProvider
End Sub
'Depending on the legal key size limitations of a specific CryptoService provider
'and length of the private key provided, padding the secret key with space character
'to meet the legal size of the algorithm.
Private Function GetLegalKey(ByVal Key As String) As Byte()
Dim sTemp As String
If (_CryptoService.LegalKeySi
Dim lessSize As Integer = 0
Dim moreSize As Integer = _CryptoService.LegalKeySiz
'key sizes are in bits
Do While (Key.Length * 8 > moreSize)
lessSize = moreSize
moreSize += _CryptoService.LegalKeySiz
Loop
sTemp = Key.PadRight(moreSize / 8, " ")
Else
sTemp = Key
End If
'convert the secret key to byte array
Return ASCIIEncoding.ASCII.GetByt
End Function
Public Function Encrypt(ByVal Source As String, ByVal Key As String) As String
Dim bytIn As Byte() = System.Text.ASCIIEncoding.
'create a MemoryStream so that the process can be done without I/O files
Dim ms As MemoryStream = New MemoryStream
Dim bytKey As Byte() = GetLegalKey(Key)
'set the private key
_CryptoService.Key = bytKey
_CryptoService.IV = bytKey
'create an Encryptor from the Provider Service instance
Dim encrypto As ICryptoTransform = _CryptoService.CreateEncry
'create Crypto Stream that transforms a stream using the encryption
Dim cs As CryptoStream = New CryptoStream(ms, encrypto, CryptoStreamMode.Write)
'write out encrypted content into MemoryStream
cs.Write(bytIn, 0, bytIn.Length)
cs.FlushFinalBlock()
'get the output and trim the '\0' bytes
Dim bytOut As Byte() = ms.GetBuffer()
Dim i As Integer = 0
For i = 0 To bytOut.Length
If bytOut(i) = 0 Then Exit For
Next
'convert into Base64 so that the result can be used in xml
Return System.Convert.ToBase64Str
End Function
Public Function Decrypt(ByVal Source As String, ByVal Key As String) As String
'convert from Base64 to binary
Dim bytIn As Byte() = System.Convert.FromBase64S
'create a MemoryStream with the input
Dim ms As MemoryStream = New MemoryStream(bytIn, 0, bytIn.Length)
Dim bytKey As Byte() = GetLegalKey(Key)
'set the private key
_CryptoService.Key = bytKey
_CryptoService.IV = bytKey
'create a Decryptor from the Provider Service instance
Dim encrypto As ICryptoTransform = _CryptoService.CreateDecry
'create Crypto Stream that transforms a stream using the decryption
Dim cs As CryptoStream = New CryptoStream(ms, encrypto, CryptoStreamMode.Read)
'read out the result from the Crypto Stream
Dim sr As StreamReader = New StreamReader(cs)
Return sr.ReadToEnd()
End Function
End Class
Once you have created this class, you can use it like this....
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim EncMyWorld As String = EncryptString("MyWorld")
Dim DecMyWorld As String = DecryptString(EncMyWorld)
End Sub '***********Put a break point here and you can examine both encrypted and decrypted values************
Private Function EncryptString(ByVal StringValue As String) As String
Dim Enc As New Encryptor(Encryptor.Provid
Dim MyWorld As String = StringValue
Dim EncryptedMyWorld As String = Enc.Encrypt(MyWorld, "MyWorld")
Return EncryptedMyWorld
End Function
Private Function DecryptString(ByVal EncryptedStringValue As String) As String
Dim Enc As New Encryptor(Encryptor.Provid
Dim EncMyWorld As String = EncryptedStringValue
Dim DecryptedMyWorld As String = Enc.Decrypt(EncMyWorld, "MyWorld")
Return DecryptedMyWorld
End Function
I trust this will be helpful
Kind Regards...
Business Accounts
Answer for Membership
by: akosterPosted on 2009-10-12 at 07:16:24ID: 25551410
You can use a hash code to verify that that a user inputted string matches "Hello world", but a hash cannot be 'dehashed' into its original form.
For that you will need to use encryption or if security is not an issue use binary serialization