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


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



Relevant Pages

  • Re: Byte array to string and back - newbie question
    ... // Create a symmetric algorithm. ... This is done to make encryption more ... // Encrypt a string into a string using a password ... // Decrypt a byte array into a byte array using a key and an IV ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Using Python To Create An Encrypted Container
    ... an encrypted archive utility designed for secure archiving ... A match string allows you to only extract files matching a given ... Encrypt the string s using passwd and encryption cipher enc ...
    (comp.lang.python)
  • Re: How good an encryption algorithm is this?
    ... As long as the string can be converted to/from a byte stream, ... then you can apply that after the encryption. ... > So I decided to invent my own algorithm, and I just wanted anybody's> opinion on how secure this could be compared to the Win32 API version. ... > HCRYPTHASH hCryptHash; ...
    (microsoft.public.vc.language)
  • Length of the data to decrypt is invalid
    ... I found this code on a site for doing string encryption/decryption. ... // Create a symmetric algorithm. ... // This is done to make encryption more secure. ... // This will tell it that we have done our decryption ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Web app security
    ... public static string EncryptToBase64String(string stringToEncrypt, ... we'd also like to move on to better encryption such ... to make the.NET AES encryption to work together with the AES encryption ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework.aspnet)