c# - SHA1 hash translated to invalid xml -


I have a dictionary, which I change in XML and then hashes with SHA1.

  string xmlMessageCode = inputDictionary.ToXML (); // Extension method Unicode encoding UI = new Unicode encoding (); SHA1 Managed Hashter = SHA1 Managed (); Byte [] hash string = encoding. UTF8.GetBytes (xmlMessageCode.ToCharArray ()); Byte [] Hashod = Hashar Compact hash (hash string); String computed hash string = UTF 8 encoding. UTF 8.Greatstring (Hashodod); Hashstring calculated; After this, I put the values ​​in an object property and then serialized an archive of these objects XML:  
  XmlSerializer ser = new XmlSerializer ( Typeof (t)); XmlWriterSettings Settings = New XmlWriterSettings () {Indent = false, OmitXmlDecleration = false, encoding = encoding.UTF8}; (Using stringbrokers SR = new stringworator) (xmlrmmml = xmlrtrttrt (sr, settings)). {Ser.Serialize (SR, newList); } Return sr.ToString (); }   

It produces XML, but when I try to validate the resulting XML, I get an error inside that property that was created from the hash string.

What is the best way to solve this? Should I strip invalid characters or is there a more elegant solution? XML is a text based representation - you can not embed binary information directly into it

Must be changed into a lesson - Base 64 encoding is usually used for that purpose.

Therefore

  string has been calculated hashstrings = UTF8Encoding.UTF8.GetString (hash);   

should be used

  string computedHashString = System.Convert.ToBase64String (hashCode);    

Comments