Encryption
-
I've spent most of the afternoon searching and looking at all kinds of encryption classes. I know that encryption can be a very detailed topic and it should be, but I'm just looking for something simple. I want to take a text string 'The cat ate the mouse' and convert it to a SHA2 hex string that I can then store into a database. Is there code to simply just do this? I've downloaded all kind of samples which have classes involved that are several pages of code. It's got to be simpler than this? Or of course then it might not be secure if it is too simple to encrypt / decrypt. Any suggestions on something simple would be helpful? :confused:
Lost in the vast sea of .NET
-
I've spent most of the afternoon searching and looking at all kinds of encryption classes. I know that encryption can be a very detailed topic and it should be, but I'm just looking for something simple. I want to take a text string 'The cat ate the mouse' and convert it to a SHA2 hex string that I can then store into a database. Is there code to simply just do this? I've downloaded all kind of samples which have classes involved that are several pages of code. It's got to be simpler than this? Or of course then it might not be secure if it is too simple to encrypt / decrypt. Any suggestions on something simple would be helpful? :confused:
Lost in the vast sea of .NET
You can use a function like the following:
Public Shared Function EncryptSHA512(ByVal strAs String) As String
Dim Bytes() As Byte
Dim Encoder As New System.Text.UTF8Encoding
Dim SHA512 As New System.Security.Cryptography.SHA512Managed
Dim SHA512String As StringBytes = Encoder.GetBytes(str) Bytes = SHA512.ComputeHash(Bytes) SHA512String = Convert.ToBase64String(Bytes) Return SHA512String End Function
Alexei Rodriguez
-
I've spent most of the afternoon searching and looking at all kinds of encryption classes. I know that encryption can be a very detailed topic and it should be, but I'm just looking for something simple. I want to take a text string 'The cat ate the mouse' and convert it to a SHA2 hex string that I can then store into a database. Is there code to simply just do this? I've downloaded all kind of samples which have classes involved that are several pages of code. It's got to be simpler than this? Or of course then it might not be secure if it is too simple to encrypt / decrypt. Any suggestions on something simple would be helpful? :confused:
Lost in the vast sea of .NET
-
You can use a function like the following:
Public Shared Function EncryptSHA512(ByVal strAs String) As String
Dim Bytes() As Byte
Dim Encoder As New System.Text.UTF8Encoding
Dim SHA512 As New System.Security.Cryptography.SHA512Managed
Dim SHA512String As StringBytes = Encoder.GetBytes(str) Bytes = SHA512.ComputeHash(Bytes) SHA512String = Convert.ToBase64String(Bytes) Return SHA512String End Function
Alexei Rodriguez
This function is exactly what I was looking for. Currently I'm writing a test application that simply has a form and two buttons, encrypt and decrypt. The encrypt works great with this function, but when I try to write the decrypt function everything works, but I can't find logic to reverse the ComputeHash code? Below is what I have:
Public Shared Function DecryptSHA512(ByVal str As String) As String Dim Bytes() As Byte Dim Encoder As New System.Text.UTF8Encoding Dim SHA512 As New System.Security.Cryptography.SHA512Managed Dim RegularString As String Bytes = Convert.FromBase64String(str) 'Bytes = SHA512.??(Bytes) 'Can't find reverse logic RegularString = Encoder.GetString(Bytes) Return RegularString End Function
Thanks again for the code you have given and any suggestions on the decrypt logic is welcome :)Lost in the vast sea of .NET
-
This function is exactly what I was looking for. Currently I'm writing a test application that simply has a form and two buttons, encrypt and decrypt. The encrypt works great with this function, but when I try to write the decrypt function everything works, but I can't find logic to reverse the ComputeHash code? Below is what I have:
Public Shared Function DecryptSHA512(ByVal str As String) As String Dim Bytes() As Byte Dim Encoder As New System.Text.UTF8Encoding Dim SHA512 As New System.Security.Cryptography.SHA512Managed Dim RegularString As String Bytes = Convert.FromBase64String(str) 'Bytes = SHA512.??(Bytes) 'Can't find reverse logic RegularString = Encoder.GetString(Bytes) Return RegularString End Function
Thanks again for the code you have given and any suggestions on the decrypt logic is welcome :)Lost in the vast sea of .NET