public AdESResult XAdESSign(byte[] dataToSign, XAdESSignatureContext signatureContext) { AdESResult result; #if NET5_0 using (dynamic wr = CLRLoader.CLRLibrary .CreateCLRInstance(BaseConstants.AdESCLRWrapperClassName)) #else using (dynamic wr = CLRLoader.CLRFrameworkLibrary .CreateCLRInstance(BaseConstants.AdESCLRFrameworWrapperClassName)) #endif { wr.IsDebug = false; var coreSignatureContext = signatureContext.ConvertXAdESSignatureContext(); var coreResult = wr.XAdESSign(dataToSign, coreSignatureContext); result = DataConversion.ConvertAdESResult(coreResult); } return(result); }
public void XAdESSignTest() { byte[] certHas = GetCertHash("3bd3f17836bd00f8a756e6c53fca48539da2f042"); // XAdES ////////////////// // Get data to sign from file var xdfDataToSign = File.ReadAllBytes(inputXMLFile); // PAdES configuration var xadesSignatureContext = new XAdESSignatureContext { SigningCertificate = new CertificateIdentifier { CertificateHash = certHas }, AdESAttributes = new AdESAttributes { Level = Level.XL, HashAlgorithm = HashAlgorithm.SHA256 }, SignerAttributes = new SignerAttributes { AuthorName = "Pavel Hryzlík" }, XAdESSpecificAttributes = new XAdESSpecificAttributes { Packaging = PackagingType.Enveloped } }; // XAdES sign var xadesResult = adESProcessor.XAdESSign(xdfDataToSign, xadesSignatureContext); // Save signed data to file File.WriteAllBytes(outputXMLFile, xadesResult.signedData); }
static void Main(string[] args) { string dir = Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location); inputCMSFile = Path.Combine(dir, "..", "..", "..", "..", "..", @"test\AdESNet.TestData\hello.txt"); outputCMSFile = Path.Combine(dir, "..", "..", "..", "..", "..", @"test\AdESNet.TestData\hello_signed.p7m"); inputPDFFile = Path.Combine(dir, "..", "..", "..", "..", "..", @"test\AdESNet.TestData\hello.pdf"); outputPDFFile = Path.Combine(dir, "..", "..", "..", "..", "..", @"test\AdESNet.TestData\hello_signed.pdf"); inputXMLFile = Path.Combine(dir, "..", "..", "..", "..", "..", @"test\AdESNet.TestData\hello.xml"); outputXMLFile = Path.Combine(dir, "..", "..", "..", "..", "..", @"test\AdESNet.TestData\hello_signed.xml"); //TestCrypto32(); //var cert = GetCert(); // Cpp object using var wr = new AdESWrapper { IsDebug = true }; byte[] certHas = GetCertHash("3bd3f17836bd00f8a756e6c53fca48539da2f042"); // CAdES ////////////////// // Get data to sign from file var cmdDataToSign = File.ReadAllBytes(inputCMSFile); // CAdES configuration var cadesSignatureContext = new SignatureContext { SigningCertificate = new CertificateIdentifier { CertificateHash = certHas }, AdESAttributes = new AdESAttributes { Level = Level.XL, HashAlgorithm = HashAlgorithm.SHA256 }, SignerAttributes = new SignerAttributes { AuthorName = "Pavel Hryzlík" } }; // CAdES sign var cadesResult = wr.CAdESSign(cmdDataToSign, cadesSignatureContext); // Save signed data to file File.WriteAllBytes(outputCMSFile, cadesResult.signedData); // PAdES ////////////////// // Get data to sign from file var pdfDataToSign = File.ReadAllBytes(inputPDFFile); // PAdES configuration var padesSignatureContext = new PAdESSignatureContext { SigningCertificate = new CertificateIdentifier { CertificateHash = certHas }, AdESAttributes = new AdESAttributes { Level = Level.XL, HashAlgorithm = HashAlgorithm.SHA256 }, SignerAttributes = new SignerAttributes { AuthorName = "Pavel Hryzlík" }, PAdESSpecificAttributes = new PAdESSpecificAttributes { } }; // PAdES sign var padesResult = wr.PAdESSign(pdfDataToSign, padesSignatureContext); // Save signed data to file File.WriteAllBytes(outputPDFFile, padesResult.signedData); // XAdES ////////////////// // Get data to sign from file var xdfDataToSign = File.ReadAllBytes(inputXMLFile); // XAdES configuration var xadesSignatureContext = new XAdESSignatureContext { SigningCertificate = new CertificateIdentifier { CertificateHash = certHas }, AdESAttributes = new AdESAttributes { Level = Level.XL, HashAlgorithm = HashAlgorithm.SHA256 }, SignerAttributes = new SignerAttributes { AuthorName = "Pavel Hryzlík" }, XAdESSpecificAttributes = new XAdESSpecificAttributes { Packaging = PackagingType.Enveloped } }; // XAdES sign var xadesResult = wr.XAdESSign(xdfDataToSign, xadesSignatureContext); // Save signed data to file File.WriteAllBytes(outputXMLFile, xadesResult.signedData); }
public Task <AdESResult> XAdESSignAsync(byte[] dataToSign, XAdESSignatureContext signatureContext) { return(Task.FromResult(XAdESSign(dataToSign, signatureContext))); }
public static dynamic ConvertXAdESSignatureContext(this XAdESSignatureContext xAdESSignatureContext) { return(AutoMapper.Map(xAdESSignatureContext, typeof(XAdESSignatureContext), Assembly.GetType(BaseConstants.XAdESSignatureContextClassName))); }