Presenter:Todd Miranda
Encrypt XML data easily with the objects available in .NET. Transmitting and saving XML data is very popular but the plain text nature of XML makes using it for sensitive data difficult. Todd Miranda demonstrates how to encrypt and decrypt XML data using Symmetric Keys.
The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video
Minute 0
Will demonstrate how to encrypt decrypt XML using this record are in him and in Visual Studio and the Visual Studio to go they used to go a create a Windows forms application of general framework intrusion to Ivory Coast were as sport here and were named this project appropriately he is in a real simple form really or place it here so and a single button and will copy that and add a second button and going this button and will say that this is the encrypt button and button to be the decrypt button and will put some event handlers
Minute 1
Or the click of a button when going to this privilege only need from the design of the form why so do we need to handle a couple of things the first thing you do for me to create an XML file or encrypt so let s go ahead and ordered to appear to project had no item XML file and was told us crypto and a typical thing that we might see it as simple like it when cryptic records and so you might have record and in here you might have the number which might case numbers here and then you might have some date as to when it expires in this might be 1010 and 2008 will say
Minute 2
Are premature we need to be able to shower and encrypt the acts of the crypto XML file and the other thing that we want to do is add a reference and or project are at a reference to the system security assembly would need that one so system security add that in their ad aware handle some extra using statement serenity saw a success for dealing with XML organ need the XML namespace answer for dealing with any kind of cryptography were in need the system security cryptography namespace and since were doing more specifically with XML cryptography system security cryptography
Minute 3
Smell an attribute which cover the photo in the priceless goer but in one click event or before do that actually Leslie and create the variable to restore symmetric key and so we re going to use a symmetric algorithm and the Smith government or a use is the what looks like written Dorel mating but is actually slept rough ride all and it was called us some key is for your ninjas can generate her symmetric key force of the rind all method is a symmetric algorithm for encryption wrestlers over the button one quicker than others or encrypt button is the first in a wanted to go to encrypt this is where one create our new key so by doing that would create a new instance of Orion doll algorithm and that will enable us to use the symmetric key that generates force
Minute 4
The extent we want to do is actually load of our XML document so we got her excellent document new XML document will do our XML doc preserve whitespace true and finally our XML doc lewd and will load that crypto XML file that we just created rights in Aligarh XML file loaded to know when to exit in cricket so it will write a method called encrypt if we haven t done yet will come back and do that correct has to with our excellent document the element that we want to encrypt which think that was critical of the credit card elements in our credit card lives and we won t pass the algorithm will use so I simply as it will past work at method when right this moment was the encrypt the Excel document them with this
Minute 5
To him about safe and will overwrite our file with the newly encrypted file solicit more to do to decrypt encrypted to look very similar on the food will create a new mind all algorithm to generate a new key for us because we will have use the same key in a symmetric algorithm effectively what a symmetric algorithm names is use the same key that she used to encrypt it to decrypt it is what that means is when you encrypted with a key some hell you ve got to keep that key you got to get it to the person that I decrypt the file and then use the same key to decrypt it orbits the same person presses all on the local machine like in this example you simply won t create this key will decrypt data with it you have to store the key somewhere oftentimes the key is his encrypted with a different type of algorithm and that stored somewhere in her crib to stay
Minute 6
In what is needed is decrypted and used to decrypt the data off the bottle I is the symmetric government means that you got the same key to decrypt that you used to encrypt so what we ve done is we ve created this global variable store the key layer that way we created to encrypt and use it to decrypt our school at little or excellent document is likely that before our crypto XML said this time with a decrypt and were not decrypting a specific element serenity crypt of the document using the algorithm is what passes to parameters and or decrypt methods were the same thing when I save it back out to the file in its new date newly decrypted state so let s start with or encrypt method so it s was like as a private and it s avoided encrypt them that free parameters are passed to hear one of those is an XML document call the doc get a win is our
Minute 7
Of ours is a string specifying the element name that we want to encrypt and the next one is our symmetric algorithm which was called out for algorithm okay so now let s look at what to do to encrypt this element within the XML is not very complicated but it can be a little intimidating if you don t know what all these classes are used to soak the sister of the top everything looked as one piece at a time of a soap summary or loss were sure to cite what we need to do is we need to get the element or to encrypt their winning to encrypt the element and the need to create some elements that are going to go back into our XML file for her even though we re we re encrypting the data in the Excel file and it was also Phillies to be valid XML soap Buddha creates an XML element for you create this encrypted data element and its stores perfectly everything about encrypted data
Minute 8
We ve got to tell it what type of encryption we used that to let the encryption method that was used to that type of element was encrypted the encryption method the actual date of the encrypted data itself and the replace the unencrypted data with the newly encrypted data to what we have still all this will only send the sex will fall somebody else in reason and some other application that application needs to know how the data was encrypted and the key is to have the capability cricket but its know how is encrypted to know how to use the key to decrypt it so let s take this one specific comment and what will refer it will be for horror for similar do is grab the XML element that one crypt so we ll call this element to encrypt and this is going to be get off my tag names are just going to ask my mom can find this particular is pure elements in
Minute 9
Are passing an element name looking for which will grab the first instance of that we don t only have one but the scheduling order in the first instance of it and we are passionate back as an XML cartoon or have her element won t encrypt to the Nixon wanted to do was encrypt it and were a use an encrypted XML object and allows us to very easily encrypt the XML data appropriately for a W3C standard for encryption aren t so that simply means their take the encrypted XML object and call a UNIX mail when you create a new instance of that and you may use this to encrypt the data us a recall in encrypt data and won t pass to encrypt data is our data that we need to encrypt so our element books and element to encrypt and walked past the key that we want to use for that
Minute 10
So call that are there for our Britain were used encrypted in a webcast of Boolean that indicates whether we want to just encrypt the content of the element or the entire element itself and which would encrypt entire elements were as false via his returns back to us a byte array or so there for a byte array in order to call this encrypted element I so we had our element to encrypt and now we have our encrypted element as a byte array that is an encrypted by Teresa was for our data is now encrypted we have the encrypted data at this point right now is stored in encrypted element variable and now we need to create this encrypted data element or put everything and so recreate the encrypted data element will call this data equals new
Minute 11
Encrypted data everything they do is tell it what type of thing is it good to hear this encrypted current so what is it distorted her descriptors or specified type and this isn t the swans of his his his his XML this looks like a URI in XML so so sure what that your looks like a more poorly on a tight fit and we have some static variables that we can use their religious string constant force so in this case really use encrypted XML and this was an element store use encrypted XML encrypted element you re a price that s all that is this is just a string constant that prevent us from having to type up a bunch of more complicated strain in here right now with the what type it is that we had to kill it with the encryption method that was used are and this is going to be new encryption method and we re passing
Minute 12
Type of encryption method that was right so again this is done via a URI type scenarios so we will have for type all that Sony used the encrypted XML some of its static strings for us and this is the AES 256 are so encrypted that with AES 256 or rind off action on exactly the same but for all intensive purposes this is the this is the category will we won t and again this spring constant so nothing magical about that just keeps rabbit type and a bunch of vote long strings aren t so now we ve encrypted data would create his encrypted data element was told that the type of elements of the type of thing that s encrypted encryption method that was used now we have to actually put the encrypted data into her crib to data element are so interpret the data element has a cipher data in one store the value of that
Minute 13
Value of that is just the encrypted element so now we stored the data into our encrypted data object or a cryptic data element so now we want to use a method of the encrypted XML call replaced element and were passing in the element to encrypt which is the one we want to replace what do one or place it with our place with our encrypted data and do our place just the contents or guitar element again falls slightly used for good or warm place in tar element and it s at that point we have encrypted data we ve put everything together what we need to do and we ve replaced the element the sacred development with our encrypted element aren t so now let s look at the decrypt methods so in our decryptor test in the XML
Minute 14
Document panel Doc and we didn t have seen the code element name because words cannot look up encrypted document and put the overwhelming need for we do need to we did pass in the such barbarism are so Nelson looked at how organ and decrypt this data back out for documents to some degree were to do things in reverse rights the first thing we do is nutrient XML element and when I grabbed the and this is the encrypted element and that is in the dock get a list by tag named Neil we encrypt the data but we cricket it into a encrypted data element so that action shows up in the XML as encrypted data alum
Minute 15
Want to grant the encrypted data element as an XML element and bring the backs of this is the element now within the XML is that has all the encrypted information in it right to next thing would do is create the actual encrypted data object and call this that equals new encrypted data is cranked right and I will load into the encrypted data first you to manually loaded us on this time we can do encrypt that load XML and what a load in the encrypted element types of nodes loaded all the encrypted stuff that we put into the encrypted data in the encrypt which is loaded that into this new encrypted data object was created art and now recreate us like we have done for recreate an encrypted XML object
Minute 16
Is new to XML and reuse that again worried about array out of this except this time or get out is the decrypted element and women do very so virtually done for when decrypted data exhibit a stoner pass the end of the encrypted data which is our think that any algorithm there were many used to decrypt it are so now we ve got our decrypted data are good for camera use another method of or encrypted XML to help us do a replace Dave and this is from your encrypted element that were replaced with our decrypted element right so that s all there is to know if we ve effectively encrypted and even reverse the process did the
Minute 17
We don t replace data replacing the encrypted element with our decrypted element in the back in our our clique of it here or after we do or decrypt RSA back out to us build and see if we ve missed anything might build succeeded let s go ahead and go her solution Explorer was right this click on a crypto XML and let s tell it to copy the output directory so we can use it when we went around us right so let s run this Reuters reform them of the open of both the directory that were working in and won t go into the bin debug area and look at decrypted XML we know what they should look like I so there is or are crypto XML looks pretty familiar notion of a fat hospital back
Minute 18
Tour for must quickly correct and was go back and look at our crypto election will and you see that our corporate court now has been replaced with encrypted data element here to fight and we would ve had to type all this and if we didn t use a string constant fear for actual namespace for this encrypted data element is the encryption method the algorithm was this would have tied all this and those who have titled this and if we knew that string constants remember your first our cipher data in its cipher value in his encrypted data so all that work we did in the encrypt actually translates to these elements here in XML rights of their encrypted XML now let s decrypt and as we back our XML file
Minute 19
And everything is fleabag decrypted the way that it was so you can see that also this can be a little confusing because there s just so many objects as you got here what is a job to do and how to use a site object the reality is it s preferred forth and break it down step by step and you look at how we use this the biggest problem with using a symmetric cover them again yet have keep in mind just use the same key right to do that used to encrypt the element to be critically ill write will hopefully that was helpful in understanding little more about encrypting and decrypting XML using a symmetric armor them if you d like to find out more or need additional resources obscure development visit WW hello secure world com
Click here to go to original video page
Tuesday, July 8, 2008
Video: How Do I: Improve Data Security by Encrypting and Decrypting XML Data Using Symmetric Keys?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment