RSA Encryption
From: KJ (klj_mcsd_at_hotmail.com)
Date: 09/28/04
- Next message: Clint: "RE: Impersonation and SQL Connections"
- Previous message: Nigel Rivett: "Re: SQL Injection Prevention"
- Next in thread: Shawn Farkas [MS]: "RE: RSA Encryption"
- Reply: Shawn Farkas [MS]: "RE: RSA Encryption"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 28 Sep 2004 11:32:22 -0700
Is RSA a good encryption method? Also I'm having a problem pulling the
string out of the database and decrypting it. Please Help
Code is below:
Private Function EncryptPassword(ByVal a_Password As String) As
String
Dim ByteConverter As New ASCIIEncoding
Dim dataToEncrypt As Byte() =
ByteConverter.GetBytes(a_Password)
Dim encryptedData() As Byte
'Create a new instance of the RSACryptoServiceProvider class
' and automatically create a new key-pair.
Dim RSAalg As New RSACryptoServiceProvider
Try
'Encrypt the byte array and specify no OAEP padding.
'OAEP padding is only available on Microsoft Windows XP or
'later.
encryptedData = RSAalg.Encrypt(dataToEncrypt, False)
'Saving this string to the database 'Should I do that?
Return ByteConverter.GetString(encryptedData)
Catch e As CryptographicException
'Catch this exception in case the encryption did
'not succeed.
' Console.WriteLine(e.Message)
End Try
End Function
Private Function DecryptPassword(ByVal strEncryptedPassword As String)
As String
'I'm passing the string that I stored in the database
Dim ByteConverter As New ASCIIEncoding
Dim decryptedData() As Byte
Dim encryptedPassword As Byte()
'Create a new instance of the RSACryptoServiceProvider class
' and automatically create a new key-pair.
Dim RSAalg As New RSACryptoServiceProvider
Try
encryptedPassword =
ByteConverter.GetBytes(strEncryptedPassword)
'Pass the data to ENCRYPT and boolean flag specifying
'no OAEP padding.
decryptedData = RSAalg.Decrypt(encryptedPassword, True)
Return ByteConverter.GetString(decryptedData)
Catch ex As CryptographicException
'Catch this exception in case the encryption did
'not succeed.
Throw ex
End Try
End Function
- Next message: Clint: "RE: Impersonation and SQL Connections"
- Previous message: Nigel Rivett: "Re: SQL Injection Prevention"
- Next in thread: Shawn Farkas [MS]: "RE: RSA Encryption"
- Reply: Shawn Farkas [MS]: "RE: RSA Encryption"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|