I think this is because during encryption, I execute [code]key = New RijndaelManaged()[/code] And, during decryption, I also execute [code]key = New RijndaelManaged()[/code] How can I save the key from the encryption ?
Thank you.

This is the code to encrypt and save the XML file: [code]Imports System.Xml Imports System.Security.Cryptography Imports System.Security.Cryptography.Xml Dim key As RijndaelManaged = Nothing ' Create a new Rijndael key. key = New RijndaelManaged() ' Load an XML document. Dim xmlDoc As New XmlDocument() xmlDoc.PreserveWhitespace = True xmlDoc.Load("myXMLFile.XML") Encrypt(xmlDoc, "myElement1", key) Encrypt(xmlDoc, "myElement2", key) xmlDoc.Save("myXMLFile.XML")[/code] This is the code to decrypt the XML file: [code]Imports System.Xml Imports System.Security.Cryptography Imports System.Security.Cryptography.Xml Dim key As RijndaelManaged = Nothing key = New RijndaelManaged() Dim xmlDoc As New XmlDocument() xmlDoc.PreserveWhitespace = True xmlDoc.Load("myXMLFile.XML") Decrypt(xmlDoc, key)[/code]"> I think this is because during encryption, I execute [code]key = New RijndaelManaged()[/code] And, during decryption, I also execute [code]key = New RijndaelManaged()[/code] How can I save the key from the encryption ?
Thank you.

This is the code to encrypt and save the XML file: [code]Imports System.Xml Imports System.Security.Cryptography Imports System.Security.Cryptography.Xml Dim key As RijndaelManaged = Nothing ' Create a new Rijndael key. key = New RijndaelManaged() ' Load an XML document. Dim xmlDoc As New XmlDocument() xmlDoc.PreserveWhitespace = True xmlDoc.Load("myXMLFile.XML") Encrypt(xmlDoc, "myElement1", key) Encrypt(xmlDoc, "myElement2", key) xmlDoc.Save("myXMLFile.XML")[/code] This is the code to decrypt the XML file: [code]Imports System.Xml Imports System.Security.Cryptography Imports System.Security.Cryptography.Xml Dim key As RijndaelManaged = Nothing key = New RijndaelManaged() Dim xmlDoc As New XmlDocument() xmlDoc.PreserveWhitespace = True xmlDoc.Load("myXMLFile.XML") Decrypt(xmlDoc, key)[/code]"> I think this is because during encryption, I execute [code]key = New RijndaelManaged()[/code] And, during decryption, I also execute [code]key = New RijndaelManaged()[/code] How can I save the key from the encryption ?
Thank you.

This is the code to encrypt and save the XML file: [code]Imports System.Xml Imports System.Security.Cryptography Imports System.Security.Cryptography.Xml Dim key As RijndaelManaged = Nothing ' Create a new Rijndael key. key = New RijndaelManaged() ' Load an XML document. Dim xmlDoc As New XmlDocument() xmlDoc.PreserveWhitespace = True xmlDoc.Load("myXMLFile.XML") Encrypt(xmlDoc, "myElement1", key) Encrypt(xmlDoc, "myElement2", key) xmlDoc.Save("myXMLFile.XML")[/code] This is the code to decrypt the XML file: [code]Imports System.Xml Imports System.Security.Cryptography Imports System.Security.Cryptography.Xml Dim key As RijndaelManaged = Nothing key = New RijndaelManaged() Dim xmlDoc As New XmlDocument() xmlDoc.PreserveWhitespace = True xmlDoc.Load("myXMLFile.XML") Decrypt(xmlDoc, key)[/code]">
I encrypt an XML file and save it to the original file.
I then open the file and try to decrypt it, and get the error "Padding is invalid and cannot be removed".
I think this is because during encryption, I execute [code]key = New RijndaelManaged()[/code] And, during decryption, I also execute [code]key = New RijndaelManaged()[/code] How can I save the key from the encryption ?
Thank you.

This is the code to encrypt and save the XML file: [code]Imports System.Xml Imports System.Security.Cryptography Imports System.Security.Cryptography.Xml Dim key As RijndaelManaged = Nothing ' Create a new Rijndael key. key = New RijndaelManaged() ' Load an XML document. Dim xmlDoc As New XmlDocument() xmlDoc.PreserveWhitespace = True xmlDoc.Load("myXMLFile.XML") Encrypt(xmlDoc, "myElement1", key) Encrypt(xmlDoc, "myElement2", key) xmlDoc.Save("myXMLFile.XML")[/code] This is the code to decrypt the XML file: [code]Imports System.Xml Imports System.Security.Cryptography Imports System.Security.Cryptography.Xml Dim key As RijndaelManaged = Nothing key = New RijndaelManaged() Dim xmlDoc As New XmlDocument() xmlDoc.PreserveWhitespace = True xmlDoc.Load("myXMLFile.XML") Decrypt(xmlDoc, key)[/code]


JLCPCB – Prototype 10 PCBs for $2 (For Any Color)

China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir