November 21, 2005 at 1:00 pm
Hello all,
I want to have a table that has one filed that holds a password that is encrypted somehow, from SQL server or C# doesnt matter. I want to be able to read from this field and decipher either on the app side or the SQL side. I would prefer the app side. Anyone have any examples of this or any suggestions?
Thanks!
-NM
November 21, 2005 at 3:38 pm
this code is in vb.net I have not program in C# for almost 2 years so i am rusted 😉
Just translate the codes of this TripleDESCrypto
'you have a ButtonEncrypt and a ButtonDecrypt you also have TextBox5 'that handle a key or a salt whatever you want to call it.
'textBox4 handle your encrypted message and TextBox3 your decrypted 'message
'enter a message in textbox3 and a key in textbox5 click encrypt then this 'will be encrypted in textbox4.
'to decrypt fill textbox4 and your salt in textbox5 and click decrypt.
Imports System.Security.Cryptography
Private Sub ButtonEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEncrypt.Click
Dim encrypt As String
Dim key As String = TextBox5.Text
Dim des As TripleDESCryptoServiceProvider
Dim hashmd5 As MD5CryptoServiceProvider
Dim pwdhash(), buff() As Byte
hashmd5 = New MD5CryptoServiceProvider
pwdhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key))
hashmd5 = Nothing
des = New TripleDESCryptoServiceProvider
des.Key = pwdhash
des.Mode = CipherMode.ECB
buff = ASCIIEncoding.ASCII.GetBytes(TextBox3.Text)
encrypt = Convert.ToBase64String(des.CreateEncryptor().TransformFinalBlock(buff, 0, buff.Length))
TextBox4.Text = encrypt
des = Nothing
End Sub
Private Sub ButtonDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDecrypt.Click
Dim decrypt As String
Dim key As String = TextBox5.Text
Dim des As TripleDESCryptoServiceProvider
Dim hashmd5 As MD5CryptoServiceProvider
Dim pwdhash(), buff() As Byte
hashmd5 = New MD5CryptoServiceProvider
pwdhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key))
hashmd5 = Nothing
des = New TripleDESCryptoServiceProvider
des.Key = pwdhash
des.Mode = CipherMode.ECB
buff = Convert.FromBase64String(TextBox4.Text)
decrypt = ASCIIEncoding.ASCII.GetString(des.CreateDecryptor().TransformFinalBlock(buff, 0, buff.Length))
TextBox3.Text = decrypt
des = Nothing
End Sub
November 22, 2005 at 7:32 am
Excellent, going to give it a try. Thanks a ton!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply