Re: RSA Encryption - What I'm I doing wrong?
From: Joe Kaplan \(MVP - ADSI\) (joseph.e.kaplan_at_removethis.accenture.com)
Date: 09/29/04
- Next message: Cor Ligthert: "Re: Validating a valid URL"
- Previous message: KJ: "RSA Encryption - What I'm I doing wrong?"
- In reply to: KJ: "RSA Encryption - What I'm I doing wrong?"
- Next in thread: Rob Teixeira [MVP]: "Re: RSA Encryption - What I'm I doing wrong?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 29 Sep 2004 09:20:26 -0500
Generally, you only use RSA for encrypting very short pieces of data like
another encryption key you use for bulk encryption.
There is a very good encryption sample from an MS employee here:
http://www.dotnetthis.com/Articles/Crypto.htm
Joe K.
"KJ" <klj_mcsd@hotmail.com> wrote in message
news:d83a9214.0409290606.3c2cdd45@posting.google.com...
> 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: Cor Ligthert: "Re: Validating a valid URL"
- Previous message: KJ: "RSA Encryption - What I'm I doing wrong?"
- In reply to: KJ: "RSA Encryption - What I'm I doing wrong?"
- Next in thread: Rob Teixeira [MVP]: "Re: RSA Encryption - What I'm I doing wrong?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|