Archived Forum Post

Index of archived forum posts

Question:

Help encryption with a third party

Apr 10 '13 at 08:49

I want to work with your rsa activex to encrypt credit cards. Example in VB is there you can get me a parallel example in Delphi?

Private Function GetEncryptedCard(ByVal cardNum As String, ByVal CVV As String, ByVal expM As String, ByVal expY As String, ByVal avrZip As String) 'GET PUBLIC KEY

    Dim publicKey_response = dinerware.GetPublicKey()
    Dim publicKey As String = publicKey_response.ToString

'TURN MINIMAL CARD TO XML STRING FOR ENCRYPTION 'VERY IMPORTANT THAT THE XML STRING IS IN THIS ORDER. ANY VARIATION WILL FAIL ON DINERWARE'S END Dim xmlCard = "<card klzzwxh:0000="" 2004="" 07="" dinerware""="" klzzwxh:0001="" 2001="" xmlschema-instance""="">" xmlCard = xmlCard + "<cvv>" + CVV + "</cvv>" xmlCard = xmlCard + "<cardnumber>" + cardNum + "</cardnumber>" xmlCard = xmlCard + "<expmonth>" + expM + "</expmonth>" xmlCard = xmlCard + "<expyear>" + expY + "</expyear>" xmlCard = xmlCard + "<avrzip>" + avrZip + "</avrzip>" xmlCard = xmlCard + "</card>"

'GENERATE KEYS 'CRYPTO STUFF Dim m_cryptoProvider As New TripleDESCryptoServiceProvider

    m_cryptoProvider.GenerateIV()
    m_cryptoProvider.GenerateKey()

    Dim m_key() As Byte = m_cryptoProvider.Key
    Dim m_iv() As Byte = m_cryptoProvider.IV

    Dim theEncryptor As ICryptoTransform
    theEncryptor = m_cryptoProvider.CreateEncryptor(m_key, m_iv)

    Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream
    Dim cryptoStream As CryptoStream = _
    New CryptoStream(stream, theEncryptor, _
                          CryptoStreamMode.Write)

    Dim Input() As Byte = System.Text.Encoding.Default.GetBytes(xmlCard)

    cryptoStream.Write(Input, 0, Input.Length)
    cryptoStream.FlushFinalBlock()

    Dim EncryptedCard = System.Convert.ToBase64String(stream.ToArray())

    'make a buffer containing the random IV and Key
    Dim keybuffer(31) As Byte
    Array.Copy(m_key, keybuffer, m_key.Length)
    Array.Copy(m_iv, 0, keybuffer, 24, m_iv.Length)

    'takes byte array
    'returns a base64 encoding of the encrypted string, so it'll be XML-friendly
    'new RSA Provider
    Dim m_RSAcryptoProvider As New RSACryptoServiceProvider(512)
    m_RSAcryptoProvider.FromXmlString(publicKey)

Dim output() As Byte Try output = m_RSAcryptoProvider.Encrypt(keybuffer, False) 'we use false because we can't assume XP or later Catch ex As Exception output = Nothing End Try

Dim encrypted_key_pair = System.Convert.ToBase64String(output)

Dim theEncryptedCard = "<encrypted key="" "="" +encrypted_key_pair+"""="">"+EncryptedCard+"</encrypted>"

Return (theEncryptedCard)

End Function