none
i am decrypting the credit card number and storing it in a JSON string but the decryption is not working properly . RRS feed

  • Question

  • 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/ns:Profile/ns:Customer/ns:PaymentForm[" & n & "]")) Then

                            EncryptedCCNumber = GetNode(strXml, "//ns:OTA_ProfileCreateRQ/ns:Profile/ns:Customer/ns:PaymentForm[" & n & "]/ns:PaymentCard/ns:CardNumber").Attributes("EncryptedValue").Value
                            DecryptedVal = Decrypt(EncryptedCCNumber, privateKeyFile)

                            strCardNumber = DecryptedVal
                          
                            strVendor = ReformatCCVendor(GetNode(strXml, "//ns:OTA_ProfileCreateRQ/ns:Profile/ns:Customer/ns:PaymentForm[" & n & "]/ns:PaymentCard/ns:CardType").Attributes("Code").Value)
                           
                            getvalue = GetNode(strXml, "//ns:OTA_ProfileCreateRQ/ns:Profile/ns:Customer/ns:PaymentForm[" & n & "]/ns:PaymentCard").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/ns:Profile/ns:Customer/ns:PaymentForm[" & n & "]/ns:PaymentCard/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


    Tuesday, September 24, 2019 10:58 AM

All replies

  • Hello,

    Since you are coding in VB.NET I'm moving your question to the VB.NET Forum.



    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, September 24, 2019 11:34 AM
    Moderator