Asked by:
Search in GetElementsByTagName

Question
-
User-1738841732 posted
Here is my Code below, where is need capture words like CARD/ SSN in GetElementsByTagName* SensitiveInfo can be any thing like card#, accountHorderCardNumber, PersonSSN or SSN#I have TWO requirements.1. I need a function that works like %card% and like %SSN%, in SQLDim strSensitiveInfo as stringDim xml As XmlDocument = New XmlDocument()xml.LoadXml(strReturn)For Each ElementoProyecto As XmlElement In xmlDim EleProyecto As XmlNodeList = ElementoProyecto.GetElementsByTagName("SensitiveInfo")strSensitiveInfo= If((EleProyecto(0) Is Nothing), "", EleProyecto(0).InnerText)2. I need to encrypt the value of strSensitiveInfoCan some one plz help me out on thisThursday, February 14, 2019 4:30 PM
All replies
-
User-2054057000 posted
You are asking how to select a particular element from DOM. I recommend you to use jQuery Selector which are much easier to use when selecting particular elements.
Like if you want to select:
<div id="pastingspan1"> </div>
Then you can do it like:
alert($("#pastingspan1").html());
Regards...
Thursday, February 14, 2019 4:51 PM -
User-1738841732 posted
I want to do in the code behind
Thursday, February 14, 2019 4:55 PM -
User475983607 posted
We can't read your original post.
Here is my Code below, where is need capture words like CARD/ SSN in GetElementsByTagName
* SensitiveInfo can be any thing like card#, accountHorderCardNumber, PersonSSN or SSN#
I have TWO requirements.
1. I need a function that works like %card% and like %SSN%, in SQLDim strSensitiveInfo as string Dim xml As XmlDocument = New XmlDocument() xml.LoadXml(strReturn) For Each ElementoProyecto As XmlElement In xml Dim EleProyecto As XmlNodeList = ElementoProyecto.GetElementsByTagName("SensitiveInfo") strSensitiveInfo= If((EleProyecto(0) Is Nothing), "", EleProyecto(0).InnerText)
2. I need to encrypt the value of strSensitiveInfo
Can some one plz help me out on this.NET has rich XML support. Please see the docs. I imagine Linq to SQL woul dbe easier than XmlDocument which uses XPath.
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/linq/
Other references.
https://docs.microsoft.com/en-us/dotnet/standard/data/xml/
https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmldocument?view=netframework-4.7.2
Encryption reference
https://docs.microsoft.com/en-us/dotnet/standard/security/cryptography-model
Thursday, February 14, 2019 5:47 PM -
User475983607 posted
mansooraabid
I want to do in the code behind
See the following.
Imports Newtonsoft Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Imports System Imports System.IO Imports System.Security.Cryptography Imports System.Xml.Serialization Module Module1 Sub Main() Dim password As String = "password" Dim wrapper As New Simple3Des(password) Dim strXML As String = "<NewDataSet> <CUSTOMERINFO> <CARD_NUMBER>12121212121212</CARD_NUMBER> <TYPE_OF_CARD>VI</TYPE_OF_CARD> <CARD_EXPIRATION_DATE>0623</CARD_EXPIRATION_DATE> <BANK_ACCOUNT_NUMBER>2036220196290</BANK_ACCOUNT_NUMBER> <ACCOUNT_STATUS>A</ACCOUNT_STATUS> <IS_DEFAULT>N</IS_DEFAULT> <OPTION_TYPE>R</OPTION_TYPE> <CREATED_DATE>2016-04-11T11:02:13-04:00</CREATED_DATE> <ACCOUNTREFID>100001</ACCOUNTREFID> <ENTITY>BILLPAY</ENTITY> <VALUE>9950</VALUE> </CUSTOMERINFO> </NewDataSet>" Dim ds As NewDataSet Dim serializer As New XmlSerializer(GetType(NewDataSet)) Using reader As TextReader = New StringReader(strXML) ds = serializer.Deserialize(reader) End Using ds.CUSTOMERINFO.CARD_NUMBER = wrapper.EncryptData(ds.CUSTOMERINFO.CARD_NUMBER) ds.CUSTOMERINFO.TYPE_OF_CARD = wrapper.EncryptData(ds.CUSTOMERINFO.TYPE_OF_CARD) ds.CUSTOMERINFO.BANK_ACCOUNT_NUMBER = wrapper.EncryptData(ds.CUSTOMERINFO.BANK_ACCOUNT_NUMBER) Using sw As StringWriter = New StringWriter() serializer.Serialize(sw, ds) Console.WriteLine(sw.ToString()) End Using End Sub End Module Public NotInheritable Class Simple3Des Private TripleDes As New TripleDESCryptoServiceProvider Sub New(ByVal key As String) ' Initialize the crypto provider. TripleDes.Key = TruncateHash(key, TripleDes.KeySize \ 8) TripleDes.IV = TruncateHash("", TripleDes.BlockSize \ 8) End Sub Private Function TruncateHash( ByVal key As String, ByVal length As Integer) As Byte() Dim sha1 As New SHA1CryptoServiceProvider ' Hash the key. Dim keyBytes() As Byte = System.Text.Encoding.Unicode.GetBytes(key) Dim hash() As Byte = sha1.ComputeHash(keyBytes) ' Truncate or pad the hash. ReDim Preserve hash(length - 1) Return hash End Function Public Function EncryptData( ByVal plaintext As String) As String ' Convert the plaintext string to a byte array. Dim plaintextBytes() As Byte = System.Text.Encoding.Unicode.GetBytes(plaintext) ' Create the stream. Dim ms As New System.IO.MemoryStream ' Create the encoder to write to the stream. Dim encStream As New CryptoStream(ms, TripleDes.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write) ' Use the crypto stream to write the byte array to the stream. encStream.Write(plaintextBytes, 0, plaintextBytes.Length) encStream.FlushFinalBlock() ' Convert the encrypted stream to a printable string. Return Convert.ToBase64String(ms.ToArray) End Function Public Function DecryptData( ByVal encryptedtext As String) As String ' Convert the encrypted text string to a byte array. Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext) ' Create the stream. Dim ms As New System.IO.MemoryStream ' Create the decoder to write to the stream. Dim decStream As New CryptoStream(ms, TripleDes.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write) ' Use the crypto stream to write the byte array to the stream. decStream.Write(encryptedBytes, 0, encryptedBytes.Length) decStream.FlushFinalBlock() ' Convert the plaintext stream to a string. Return System.Text.Encoding.Unicode.GetString(ms.ToArray) End Function End Class '''<remarks/> <System.SerializableAttribute(), _ System.ComponentModel.DesignerCategoryAttribute("code"), _ System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true), _ System.Xml.Serialization.XmlRootAttribute([Namespace]:="", IsNullable:=false)> _ Partial Public Class NewDataSet Private cUSTOMERINFOField As NewDataSetCUSTOMERINFO '''<remarks/> Public Property CUSTOMERINFO() As NewDataSetCUSTOMERINFO Get Return Me.cUSTOMERINFOField End Get Set Me.cUSTOMERINFOField = value End Set End Property End Class '''<remarks/> <System.SerializableAttribute(), _ System.ComponentModel.DesignerCategoryAttribute("code"), _ System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=true)> _ Partial Public Class NewDataSetCUSTOMERINFO Private cARD_NUMBERField As String Private tYPE_OF_CARDField As String Private cARD_EXPIRATION_DATEField As UShort Private bANK_ACCOUNT_NUMBERField As String Private aCCOUNT_STATUSField As String Private iS_DEFAULTField As String Private oPTION_TYPEField As String Private cREATED_DATEField As Date Private aCCOUNTREFIDField As UInteger Private eNTITYField As String Private vALUEField As UShort '''<remarks/> Public Property CARD_NUMBER() As String Get Return Me.cARD_NUMBERField End Get Set Me.cARD_NUMBERField = Value End Set End Property '''<remarks/> Public Property TYPE_OF_CARD() As String Get Return Me.tYPE_OF_CARDField End Get Set Me.tYPE_OF_CARDField = value End Set End Property '''<remarks/> Public Property CARD_EXPIRATION_DATE() As UShort Get Return Me.cARD_EXPIRATION_DATEField End Get Set Me.cARD_EXPIRATION_DATEField = value End Set End Property '''<remarks/> Public Property BANK_ACCOUNT_NUMBER() As String Get Return Me.bANK_ACCOUNT_NUMBERField End Get Set Me.bANK_ACCOUNT_NUMBERField = Value End Set End Property '''<remarks/> Public Property ACCOUNT_STATUS() As String Get Return Me.aCCOUNT_STATUSField End Get Set Me.aCCOUNT_STATUSField = value End Set End Property '''<remarks/> Public Property IS_DEFAULT() As String Get Return Me.iS_DEFAULTField End Get Set Me.iS_DEFAULTField = value End Set End Property '''<remarks/> Public Property OPTION_TYPE() As String Get Return Me.oPTION_TYPEField End Get Set Me.oPTION_TYPEField = value End Set End Property '''<remarks/> Public Property CREATED_DATE() As Date Get Return Me.cREATED_DATEField End Get Set Me.cREATED_DATEField = value End Set End Property '''<remarks/> Public Property ACCOUNTREFID() As UInteger Get Return Me.aCCOUNTREFIDField End Get Set Me.aCCOUNTREFIDField = value End Set End Property '''<remarks/> Public Property ENTITY() As String Get Return Me.eNTITYField End Get Set Me.eNTITYField = value End Set End Property '''<remarks/> Public Property VALUE() As UShort Get Return Me.vALUEField End Get Set Me.vALUEField = value End Set End Property End Class
Result
<?xml version="1.0" encoding="utf-16"?> <NewDataSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <CUSTOMERINFO> <CARD_NUMBER>zdnhaB65EHOoLWYOpML7V1ROu7c9V9iT3vyWY5cJXQo=</CARD_NUMBER> <TYPE_OF_CARD>PgPmHxLGl08=</TYPE_OF_CARD> <CARD_EXPIRATION_DATE>623</CARD_EXPIRATION_DATE> <BANK_ACCOUNT_NUMBER>K2e6athQ0IOX2MZ8+vjy5uHu6BCnRZGCvJQpCzEjPbw=</BANK_ACCOUNT_NUMBER> <ACCOUNT_STATUS>A</ACCOUNT_STATUS> <IS_DEFAULT>N</IS_DEFAULT> <OPTION_TYPE>R</OPTION_TYPE> <CREATED_DATE>2016-04-11T11:02:13-04:00</CREATED_DATE> <ACCOUNTREFID>100001</ACCOUNTREFID> <ENTITY>BILLPAY</ENTITY> <VALUE>9950</VALUE> </CUSTOMERINFO> </NewDataSet> Press any key to continue . . .
Reference docs
https://docs.microsoft.com/en-us/dotnet/standard/serialization/examples-of-xml-serialization
Thursday, February 14, 2019 7:42 PM