Esempio n. 1
0
        public void GetDigitalSignatureCertificates_MyStoreCurrentUser_CertificatesListed()
        {
            IEnumerable <X509Certificate2> certificates = DigitalSignatureManager.GetDigitalSignatureCertificates();

            foreach (X509Certificate2 certificate in certificates)
            {
                _output.WriteLine(certificate.ToString());
            }
        }
Esempio n. 2
0
        public void Sign_UnsignedWorkbook_SuccessfullySigned()
        {
            // Load our unsigned Excel workbook into a MemoryStream for processing.
            const string path = "Resources\\UnsignedWorkbook.xlsx";

            using MemoryStream stream = FileCloner.ReadAllBytesToMemoryStream(path);

            // Open the SpreadsheetDocument on the MemoryStream and sign it, using
            // the first digital signature certificate that we find.
            using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(stream, true))
            {
                X509Certificate2 certificate = DigitalSignatureManager.GetDigitalSignatureCertificates().First();
                DigitalSignatureManager.Sign(spreadsheetDocument, certificate);
            }

            // Save the signed Excel workbook to disk. When you open this workbook,
            // Excel should tell you that it has found a valid signature.
            File.WriteAllBytes("SignedWorkbook.xlsx", stream.ToArray());
        }