RSA Encryption

From: KJ (klj_mcsd_at_hotmail.com)
Date: 09/28/04


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



Relevant Pages

  • Re: A little Rolodex [revised]
    ... including alpha sort and searching for any embedded string, ... In this application, a database is a directory, ... you may optionally provide any alternate UCASE program, ... NN -> first store NN as key length ...
    (comp.sys.hp48)
  • Re: return multiple rows from sql statement
    ... strings from input values is almost certainly a safe path to SQL ... Also, being a MySQL function, it knows what MySQL needs or uses. ... All characters that are entered in the fields make their way into the database unaltered. ... The insert of what surprisinlgly was NOT a syntax error, but a string called "mysql_insert_id" into an integer field resulted in the value zero being put in. ...
    (comp.lang.php)
  • Re: Invalid variant type conversion
    ... because within regular programming, there would be no agreement upon what ... applications built by standard Delphi controls, ... NULL is the same as "" in a database. ... >> The empty string tells it all. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Code to delete/unlink Linked tables
    ... Public intLinkODBCTables As Variant, intLinkDB2Tables As Variant ... Public strLinkBackendDB As String, strLinkDSNname As String, strLinkLibName ... ' MsgBox "This database is in MDE format...I will delete/recreate ODBC ... Public Sub fncLinkDB2Table() ...
    (microsoft.public.access.modulesdaovba)
  • Re: Establish connection with and transferring data to Access
    ... The specific problem with your code is that you need to quote string ... Dim vConnection As New ADODB.Connection ... Experiment with the object model or check the documentation for the ... Doug's code opens and writes to an existing database. ...
    (microsoft.public.word.vba.general)