/// <summary> /// Load state from an XML element /// </summary> /// <param name="xmlElement">XML element containing new state</param> public void LoadXml(System.Xml.XmlElement xmlElement) { XmlNamespaceManager xmlNamespaceManager; XmlNodeList xmlNodeList; if (xmlElement == null) { throw new ArgumentNullException("xmlElement"); } xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable); xmlNamespaceManager.AddNamespace("ds", SignedXml.XmlDsigNamespaceUrl); xmlNodeList = xmlElement.SelectNodes("ds:DigestMethod", xmlNamespaceManager); if (xmlNodeList.Count == 0) { throw new CryptographicException("DigestMethod missing"); } this.digestMethod = new DigestMethod(); this.digestMethod.LoadXml((XmlElement)xmlNodeList.Item(0)); xmlNodeList = xmlElement.SelectNodes("ds:DigestValue", xmlNamespaceManager); if (xmlNodeList.Count == 0) { throw new CryptographicException("DigestValue missing"); } this.digestValue = Convert.FromBase64String(xmlNodeList.Item(0).InnerText); }
public static byte[] ComputeHashValue(byte[] value, DigestMethod digestMethod) { using (var alg = DigestUtil.GetHashAlg(digestMethod)) { return alg.ComputeHash(value); } }
public static HashAlgorithm GetHashAlg(DigestMethod digestMethod) { if (digestMethod == DigestMethod.SHA1) { return SHA1.Create(); } else if (digestMethod == DigestMethod.SHA256) { return SHA256.Create(); } else if (digestMethod == DigestMethod.SHA512) { return SHA512.Create(); } else { throw new Exception("Algoritmo no soportado"); } }
/// <summary> /// Default constructor /// </summary> public DigestAlgAndValueType() { this.digestMethod = new DigestMethod(); this.digestValue = null; }
public static void SetCertDigest(byte[] rawCert, DigestMethod digestMethod, DigestAlgAndValueType destination) { string digestAlgorithm = null; switch (digestMethod) { case DigestMethod.SHA1: digestAlgorithm = FirmaXades.SHA1Uri; break; case DigestMethod.SHA256: digestAlgorithm = FirmaXades.SHA256Uri; break; case DigestMethod.SHA512: digestAlgorithm = FirmaXades.SHA512Uri; break; } SetCertDigest(rawCert, digestAlgorithm, destination); }