public ExtendSignatures ( Document document, Document originalData, |
||
document | Document | |
originalData | Document | |
parameters | ||
리턴 | Document |
/// <summary><inheritDoc></inheritDoc></summary> /// <exception cref="System.IO.IOException"></exception> protected override Document SignDocumentInternal(Document document, SignatureParameters parameters, DigestSigner signer) { if (parameters.SignaturePackaging != SignaturePackaging.ENVELOPING && parameters.SignaturePackaging != SignaturePackaging.DETACHED) { throw new ArgumentException("Unsupported signature packaging " + parameters.SignaturePackaging); } ExternalDigestSigner factory = new ExternalDigestSigner(signer, parameters); CmsSignedDataGenerator generator = CreateCMSSignedDataGenerator( factory, parameters, GetSigningProfile(parameters), true, null); byte[] toBeSigned = Streams.ReadAll(document.OpenStream()); var content = new CmsProcessableByteArray(toBeSigned); CmsSignedData data = generator.Generate(content, parameters.SignaturePackaging != SignaturePackaging.DETACHED); Document signedDocument = new CMSSignedDocument(data); CAdESSignatureExtension extension = GetExtensionProfile(parameters); if (extension != null) { signedDocument = extension.ExtendSignatures( new CMSSignedDocument(data), document, parameters); } return(signedDocument); }
/// <summary>Add a signature to the already CMS signed data document.</summary> /// <remarks>Add a signature to the already CMS signed data document.</remarks> /// <param name="_signedDocument"></param> /// <param name="parameters"></param> /// <param name="signatureValue"></param> /// <returns></returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual Document AddASignatureToDocument(Document _signedDocument, SignatureParameters parameters, byte[] signatureValue) { if (parameters.SignaturePackaging != SignaturePackaging.ENVELOPING) { throw new ArgumentException("Unsupported signature packaging " + parameters.SignaturePackaging); } try { CmsSignedData originalSignedData = null; using (var stream = _signedDocument.OpenStream()) { originalSignedData = new CmsSignedData(stream); } //jbonilla - No aplica para C# //string jsAlgorithm = parameters.GetSignatureAlgorithm().GetJavaSignatureAlgorithm // (parameters.GetDigestAlgorithm()); //PreComputedContentSigner cs = new PreComputedContentSigner(jsAlgorithm, signatureValue // ); PreComputedSigner s = new PreComputedSigner(signatureValue); //DigestCalculatorProvider digestCalculatorProvider = new BcDigestCalculatorProvider // (); //CMSSignedDataGenerator generator = CreateCMSSignedDataGenerator(cs, digestCalculatorProvider // , parameters, GetSigningProfile(parameters), true, originalSignedData); CmsSignedDataGenerator generator = CreateCMSSignedDataGenerator(s, parameters , GetSigningProfile(parameters), true, originalSignedData); //if (originalSignedData == null || originalSignedData.SignedContent.GetContent // () == null) if (originalSignedData == null || originalSignedData.SignedContent == null) { throw new RuntimeException("Cannot retrieve orignal content"); } //byte[] octetString = (byte[])originalSignedData.SignedContent.GetContent(); //CmsProcessableByteArray content = new CmsProcessableByteArray(octetString); CmsProcessable content = originalSignedData.SignedContent; CmsSignedData data = generator.Generate(content, true); Document signedDocument = new CMSSignedDocument(data); CAdESSignatureExtension extension = GetExtensionProfile(parameters); if (extension != null) { signedDocument = extension.ExtendSignatures(new CMSSignedDocument(data), null, parameters); } return(signedDocument); } catch (CmsException e) { throw new RuntimeException(e); } }
/// <exception cref="System.IO.IOException"></exception> public virtual Document ExtendDocument(Document document, Document originalDocument , SignatureParameters parameters) { CAdESSignatureExtension extension = GetExtensionProfile(parameters); if (extension != null) { return(extension.ExtendSignatures(document, originalDocument, parameters)); } else { LOG.Info("No extension for " + parameters.SignatureFormat); } return(document); }
/// <summary><inheritDoc></inheritDoc></summary> /// <exception cref="System.IO.IOException"></exception> public virtual Document SignDocument(Document document, SignatureParameters parameters , byte[] signatureValue) { if (parameters.SignaturePackaging != SignaturePackaging.ENVELOPING && parameters .SignaturePackaging != SignaturePackaging.DETACHED) { throw new ArgumentException("Unsupported signature packaging " + parameters.SignaturePackaging); } try { //jbonilla - No aplica para C# //string jsAlgorithm = parameters.GetSignatureAlgorithm().GetJavaSignatureAlgorithm // (parameters.GetDigestAlgorithm()); //PreComputedContentSigner cs = new PreComputedContentSigner(jsAlgorithm, signatureValue // ); PreComputedSigner s = new PreComputedSigner(signatureValue); //DigestCalculatorProvider digestCalculatorProvider = new BcDigestCalculatorProvider // (); //CMSSignedDataGenerator generator = CreateCMSSignedDataGenerator(cs, digestCalculatorProvider // , parameters, GetSigningProfile(parameters), true, null); CmsSignedDataGenerator generator = CreateCMSSignedDataGenerator(s, parameters , GetSigningProfile(parameters), true, null); byte[] toBeSigned = Streams.ReadAll(document.OpenStream()); CmsProcessableByteArray content = new CmsProcessableByteArray(toBeSigned); bool includeContent = true; if (parameters.SignaturePackaging == SignaturePackaging.DETACHED) { includeContent = false; } CmsSignedData data = generator.Generate(content, includeContent); Document signedDocument = new CMSSignedDocument(data); CAdESSignatureExtension extension = GetExtensionProfile(parameters); if (extension != null) { signedDocument = extension.ExtendSignatures(new CMSSignedDocument(data), document , parameters); } return(signedDocument); } catch (CmsException e) { throw new RuntimeException(e); } }