Exemple #1
0
        public void Sign_CertificateNotPassed_Success()
        {
            const string path = "Resources\\UnsignedDocument.docx";

            using MemoryStream stream = FileCloner.CopyFileStreamToMemoryStream(path);

            using (OpenXmlPackage openXmlPackage = Open(stream, true, path))
            {
                PackageDigitalSignature signature = OpenXmlDigitalSignatureManager.Sign(openXmlPackage);

                VerifyResult verifyResult = signature.Verify();
                Assert.Equal(VerifyResult.Success, verifyResult);
            }

            File.WriteAllBytes("OpenXml_CertNotPassed_SignedDocument.docx", stream.ToArray());
        }
Exemple #2
0
        public void Sign_CertificatePassed_Success(string sourcePath, string destPath)
        {
            using MemoryStream stream = FileCloner.CopyFileStreamToMemoryStream(sourcePath);

            using (OpenXmlPackage openXmlPackage = Open(stream, true, sourcePath))
            {
                X509Certificate2 certificate = DigitalSignatureManager
                                               .GetSigningCertificates()
                                               .OfType <X509Certificate2>()
                                               .First();

                PackageDigitalSignature signature = OpenXmlDigitalSignatureManager.Sign(openXmlPackage, certificate);

                VerifyResult verifyResult = signature.Verify();
                Assert.Equal(VerifyResult.Success, verifyResult);
            }

            File.WriteAllBytes(destPath, stream.ToArray());
        }