Encrypt/decrypt info from form

Discussion in 'ASP .Net' started by Mark, Feb 6, 2004.

  1. Mark

    Mark Guest

    Hi - I have SSL, and need to collect credit card details for futher
    processing for a client.

    Although I have SSL, I still want to ensure the database holds encrypted
    data too - can anyone point me to some code, or hints for encrypting the
    data before storing it in the database - and then to be able to decrypt
    again?

    Thanks for any help,



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Mark, Feb 6, 2004
    #1
    1. Advertising

  2. Below is some encryption code I got from somewhere in the past. There is an
    encryption function and a decryption function.
    Key can be any string you want, e.g., Key = "19AKUpr7". You just have to
    use the same key to decrypt as you did to encrypt.

    There is one thing to watch for, though. When working with encrypting
    querystrings in WebForms, I found that to avoid errors in the decryption
    function you had to replace any spaces in the string to be decrypted with a
    + sign. I did not have this problem using the encryption and decryption
    routines with Windows Forms.

    Private Function EncryptTripleDES(ByVal Plaintext As String, ByVal Key As
    String) As String
    Dim DES As New
    System.security.Cryptography.TripleDESCryptoServiceProvider
    Dim hashMD5 As New
    System.security.Cryptography.MD5CryptoServiceProvider
    DES.Key =
    hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(Key))
    DES.Mode = System.Security.Cryptography.CipherMode.ECB
    Dim DESEncrypt As System.security.Cryptography.ICryptoTransform =
    DES.CreateEncryptor()
    Dim Buffer() As Byte =
    System.Text.ASCIIEncoding.ASCII.GetBytes(Plaintext)
    EncryptTripleDES = Convert.ToBase64String( _
    DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
    End Function

    ------

    Private Function DecryptTripleDES(ByVal base64Text As String, ByVal Key As
    String) As String
    Dim DES As New
    System.security.Cryptography.TripleDESCryptoServiceProvider
    Dim hashMD5 As New
    System.security.Cryptography.MD5CryptoServiceProvider
    DES.Key =
    hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(Key))
    DES.Mode = System.Security.Cryptography.CipherMode.ECB
    Dim DESDecrypt As System.security.Cryptography.ICryptoTransform =
    DES.CreateDecryptor()
    Dim Buffer() As Byte = Convert.FromBase64String(base64Text)
    DecryptTripleDES = System.Text.ASCIIEncoding.ASCII.GetString( _
    DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
    End Function




    "Mark" <> wrote in message
    news:...
    > Hi - I have SSL, and need to collect credit card details for futher
    > processing for a client.
    >
    > Although I have SSL, I still want to ensure the database holds encrypted
    > data too - can anyone point me to some code, or hints for encrypting the
    > data before storing it in the database - and then to be able to decrypt
    > again?
    >
    > Thanks for any help,
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    William LaMartin, Feb 6, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    491
    Jonathan Allen
    Sep 25, 2004
  2. =?Utf-8?B?TWlrZQ==?=
    Replies:
    0
    Views:
    955
    =?Utf-8?B?TWlrZQ==?=
    Aug 31, 2005
  3. Microsoft

    Password encrypt/decrypt

    Microsoft, Oct 5, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    7,556
    =?Utf-8?B?c3Jpbmk=?=
    Oct 5, 2005
  4. Replies:
    5
    Views:
    3,044
    srisha
    Aug 30, 2007
  5. Replies:
    1
    Views:
    431
    Daniel Martin
    Jun 16, 2007
Loading...

Share This Page