G
GUPIEZ
Guest
Xml might have multiple entries of Credit Card. It is able to decrypt but the card number reflects different numbers like 4444333322221111 becomes 4444329671171111 . in my local I created a sample app and it was working fine. The other details are coming fine .Only the credit card numbers either get jumbled up or one of them comes as empty.
GetNode is used to fetch inner text and attribute values from xml string
Protected Sub CC_Payment(ByVal version As String)
If version = CNST_V1 Then
isMigrated = True
Dim strUseForSvcFee As String = ""
Dim strUseForTransfer As String = ""
Dim strCardNumber As String = ""
Dim strExpirationMonth As String = ""
Dim strExpirationYear As String = ""
Dim strNameOnCard As String = ""
Dim strVendor As String = ""
Dim strUseforINV As String = ""
Dim strUseForCar As String = ""
Dim strUseForHTL As String = ""
Dim strUseforRAIL As String = ""
Dim strUseforWEB As String = ""
Dim EncryptedCCNumber As String = ""
Dim DecryptedVal As String = ""
Dim privateKeyFile As String = System.AppDomain.CurrentDomain.BaseDirectory + "PrivateKey2.xml"
Dim listCard As New List(Of CreditCard)
For n = 1 To 3
If Not IsNothing(GetNode(strXml, "//ns:OTA_ProfileCreateRQ/nsrofile/ns:Customer/nsaymentForm[" & n & "]")) Then
EncryptedCCNumber = GetNode(strXml, "//ns:OTA_ProfileCreateRQ/nsrofile/ns:Customer/nsaymentForm[" & n & "]/nsaymentCard/ns:CardNumber").Attributes("EncryptedValue").Value
DecryptedVal = Decrypt(EncryptedCCNumber, privateKeyFile)
strCardNumber = DecryptedVal
strVendor = ReformatCCVendor(GetNode(strXml, "//ns:OTA_ProfileCreateRQ/nsrofile/ns:Customer/nsaymentForm[" & n & "]/nsaymentCard/ns:CardType").Attributes("Code").Value)
getvalue = GetNode(strXml, "//ns:OTA_ProfileCreateRQ/nsrofile/ns:Customer/nsaymentForm[" & n & "]/nsaymentCard").Attributes("ExpireDate").Value
strExpirationYear = Mid(getvalue, 3, 2) & "#" & Left(getvalue, 4)
If strExpirationYear = "#" Then
strExpirationYear = ""
End If
strExpirationMonth = Mid(getvalue, 6, 2)
strNameOnCard = GetNode(strXml, "//ns:OTA_ProfileCreateRQ/nsrofile/ns:Customer/nsaymentForm[" & n & "]/nsaymentCard/ns:CardHolderName").InnerText
If Not String.IsNullOrEmpty(strCardNumber) OrElse Not String.IsNullOrEmpty(strNameOnCard) OrElse String.IsNullOrEmpty(strVendor) Then
Dim cards As New CreditCard
cards.Index = listCard.Count + 1
cards.CardNumber = strCardNumber
cards.ExpirationMonth = strExpirationMonth
cards.ExpirationYear = strExpirationYear
cards.NameOnCard = strNameOnCard
If Not AllElementsBlank(cards, GetType(CreditCard)) Then
listCard.Add(cards)
End If
End If
End If
Next
If Not IsNothing(listCard) AndAlso listCard.Count > 0 Then
getvalue = JsonConvert.SerializeObject(listCard)
getvalue = "{""" + "CreditCards" + """:" + getvalue + "}"
End If
Else
'Do nothing
End If
End Sub
Public Function Decrypt(ByVal EncryptedCCNumber As String, ByVal privateKeyFile As String) As String
Dim Encrypted As Byte() = Convert.FromBase64String(EncryptedCCNumber)
Dim decodedtxt As Byte()
Dim decrypted As String = ""
Using rsa = New RSACryptoServiceProvider(CInt(2048))
rsa.PersistKeyInCsp = False
Dim privateKey As String = System.IO.File.ReadAllText(privateKeyFile)
rsa.FromXmlString(privateKey)
decodedtxt = rsa.Decrypt(Encrypted, False)
End Using
decrypted = System.Text.Encoding.UTF8.GetString(decodedtxt)
Return decrypted
End Function
Continue reading...
GetNode is used to fetch inner text and attribute values from xml string
Protected Sub CC_Payment(ByVal version As String)
If version = CNST_V1 Then
isMigrated = True
Dim strUseForSvcFee As String = ""
Dim strUseForTransfer As String = ""
Dim strCardNumber As String = ""
Dim strExpirationMonth As String = ""
Dim strExpirationYear As String = ""
Dim strNameOnCard As String = ""
Dim strVendor As String = ""
Dim strUseforINV As String = ""
Dim strUseForCar As String = ""
Dim strUseForHTL As String = ""
Dim strUseforRAIL As String = ""
Dim strUseforWEB As String = ""
Dim EncryptedCCNumber As String = ""
Dim DecryptedVal As String = ""
Dim privateKeyFile As String = System.AppDomain.CurrentDomain.BaseDirectory + "PrivateKey2.xml"
Dim listCard As New List(Of CreditCard)
For n = 1 To 3
If Not IsNothing(GetNode(strXml, "//ns:OTA_ProfileCreateRQ/nsrofile/ns:Customer/nsaymentForm[" & n & "]")) Then
EncryptedCCNumber = GetNode(strXml, "//ns:OTA_ProfileCreateRQ/nsrofile/ns:Customer/nsaymentForm[" & n & "]/nsaymentCard/ns:CardNumber").Attributes("EncryptedValue").Value
DecryptedVal = Decrypt(EncryptedCCNumber, privateKeyFile)
strCardNumber = DecryptedVal
strVendor = ReformatCCVendor(GetNode(strXml, "//ns:OTA_ProfileCreateRQ/nsrofile/ns:Customer/nsaymentForm[" & n & "]/nsaymentCard/ns:CardType").Attributes("Code").Value)
getvalue = GetNode(strXml, "//ns:OTA_ProfileCreateRQ/nsrofile/ns:Customer/nsaymentForm[" & n & "]/nsaymentCard").Attributes("ExpireDate").Value
strExpirationYear = Mid(getvalue, 3, 2) & "#" & Left(getvalue, 4)
If strExpirationYear = "#" Then
strExpirationYear = ""
End If
strExpirationMonth = Mid(getvalue, 6, 2)
strNameOnCard = GetNode(strXml, "//ns:OTA_ProfileCreateRQ/nsrofile/ns:Customer/nsaymentForm[" & n & "]/nsaymentCard/ns:CardHolderName").InnerText
If Not String.IsNullOrEmpty(strCardNumber) OrElse Not String.IsNullOrEmpty(strNameOnCard) OrElse String.IsNullOrEmpty(strVendor) Then
Dim cards As New CreditCard
cards.Index = listCard.Count + 1
cards.CardNumber = strCardNumber
cards.ExpirationMonth = strExpirationMonth
cards.ExpirationYear = strExpirationYear
cards.NameOnCard = strNameOnCard
If Not AllElementsBlank(cards, GetType(CreditCard)) Then
listCard.Add(cards)
End If
End If
End If
Next
If Not IsNothing(listCard) AndAlso listCard.Count > 0 Then
getvalue = JsonConvert.SerializeObject(listCard)
getvalue = "{""" + "CreditCards" + """:" + getvalue + "}"
End If
Else
'Do nothing
End If
End Sub
Public Function Decrypt(ByVal EncryptedCCNumber As String, ByVal privateKeyFile As String) As String
Dim Encrypted As Byte() = Convert.FromBase64String(EncryptedCCNumber)
Dim decodedtxt As Byte()
Dim decrypted As String = ""
Using rsa = New RSACryptoServiceProvider(CInt(2048))
rsa.PersistKeyInCsp = False
Dim privateKey As String = System.IO.File.ReadAllText(privateKeyFile)
rsa.FromXmlString(privateKey)
decodedtxt = rsa.Decrypt(Encrypted, False)
End Using
decrypted = System.Text.Encoding.UTF8.GetString(decodedtxt)
Return decrypted
End Function
Continue reading...