public static (byte[] digest, Uri identifier) Digest(OpcPart part, HashAlgorithmName algorithmName) { var info = new HashAlgorithmInfo(algorithmName); using (var hashAlgorithm = info.Create()) { using (var partStream = part.Open()) { var digest = hashAlgorithm.ComputeHash(partStream); return(digest, info.XmlDSigIdentifier); } } }
public XmlDocument Build() { if (_objectElement == null) { throw new InvalidOperationException("A manifest has not been set on the builder."); } XmlElement keyInfoElement, signedInfo, signatureValue; var info = new HashAlgorithmInfo(_signingContext.FileDigestAlgorithmName); using (var canonicalHashAlgorithm = info.Create()) { byte[] objectElementHash; string canonicalizationMethodObjectId; using (var objectElementCanonicalData = CanonicalizeElement(_objectElement, out canonicalizationMethodObjectId)) { objectElementHash = canonicalHashAlgorithm.ComputeHash(objectElementCanonicalData); } keyInfoElement = BuildKeyInfoElement(); Stream signerInfoCanonicalStream; (signerInfoCanonicalStream, signedInfo) = BuildSignedInfoElement( (_objectElement, objectElementHash, info.XmlDSigIdentifier.AbsoluteUri, canonicalizationMethodObjectId) ); byte[] signerInfoElementHash; using (signerInfoCanonicalStream) { signerInfoElementHash = canonicalHashAlgorithm.ComputeHash(signerInfoCanonicalStream); } signatureValue = BuildSignatureValue(signerInfoElementHash); } _signatureElement.AppendChild(signedInfo); _signatureElement.AppendChild(signatureValue); _signatureElement.AppendChild(keyInfoElement); _signatureElement.AppendChild(_objectElement); _document.AppendChild(_signatureElement); return(_document); }