public void Can_Read_Add_Find_Remove_And_FindNot() { //read var certFromFile = CertUtil.GetFromFile(_certPath, _certPassword); certFromFile.Should().NotBeNull("Failed to read"); var serial = certFromFile.SerialNumber; //add CertUtil.AddCertificate(certFromFile); CertUtil.AddCertificate(certFromFile, System.Security.Cryptography.X509Certificates.StoreName.TrustedPublisher); //find var cert1 = CertUtil.GetBySerial(serial); cert1.Should().NotBeNull("Failed to add"); cert1.SerialNumber.Should().BeEquivalentTo(serial); //remove CertUtil.RemoveCertificate(serial); CertUtil.RemoveCertificate(serial, System.Security.Cryptography.X509Certificates.StoreName.TrustedPublisher); //find-not var cert2 = CertUtil.GetBySerial(serial); cert2.Should().BeNull("Failed to remove"); }
public void CanSignX(string inputName, string outputName) { var input = Path.Combine(_inputPath, inputName); var output = Path.Combine(_outputPath, outputName); if (File.Exists(output)) { File.Delete(output); } File.Exists(output).Should().BeFalse(); var signer = DocumentSigner.For(input); var cert = CertUtil.GetFromFile(_certPath, _certPassword); var serial = cert.SerialNumber; signer.Sign(input, output, cert); File.Exists(output).Should().BeTrue(); CanVerifyX(output, serial); }
public static void CreateListWatermark(string watermarkText, List <TAILIEUDINHKEM> ListTaiLieu, string Signature, string personalSign) { Application app = new Application(); try { foreach (var item in ListTaiLieu) { var doc = app.Documents.Open(FolderPath + item.DUONGDAN_FILE); try { if (doc.Bookmarks != null && !string.IsNullOrEmpty(personalSign)) { if (doc.Bookmarks["chuky"] != null) { var shape = doc.Bookmarks["chuky"].Range.InlineShapes .AddPicture(personalSign, false, true); } } //var shape = doc.Bookmarks["PicHere"].Range.InlineShapes.AddPicture(Signature, false, true); //shape.Width = 345; //shape.Height = 150; //doc.Close(); object Missing = System.Reflection.Missing.Value; object oMissing = System.Reflection.Missing.Value; object saveChanges = null; Microsoft.Office.Interop.Word.Shape nShape = null; string wmText = watermarkText; foreach (Microsoft.Office.Interop.Word.Section section in doc.Sections) { nShape = section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect( MsoPresetTextEffect.msoTextEffect1, wmText, "Calibri", (float)65, MsoTriState.msoTrue, MsoTriState.msoFalse, 0, 350, ref oMissing); nShape.Fill.Visible = MsoTriState.msoTrue; nShape.Line.Visible = MsoTriState.msoFalse; nShape.Fill.Solid(); nShape.Fill.ForeColor.RGB = (Int32)WdColor.wdColorGray35; nShape.Left = (float)WdShapePosition.wdShapeLeft; nShape.Top = 250; nShape.Rotation = -45; } object newFile = FolderPath + item.DUONGDAN_FILE; object a = 11; doc.SaveAs(ref newFile, ref a, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing); doc.Close(ref saveChanges, ref oMissing, ref oMissing); app.Quit(ref saveChanges, ref Missing, ref Missing); doc.Close(); } catch (Exception ex) { doc.Close(); } #region ap dung chu ky so if (ENABLECHUKYSO.ToIntOrZero() == 1) { FileUltilities file = new FileUltilities(); string fileinput = FolderPath + item.DUONGDAN_FILE; string fileoutput = Path.GetDirectoryName(FolderPath + item.DUONGDAN_FILE) + Path.GetFileNameWithoutExtension(FolderPath + item.DUONGDAN_FILE) + "_1.docx"; if (System.IO.File.Exists(fileoutput)) { System.IO.File.Delete(fileoutput); } var signer = DocumentSigner.For(fileinput); var cert = CertUtil.GetFromFile(CHUKYSO, PASSCHUKYSO); var serial = cert.SerialNumber; signer.Sign(fileinput, fileoutput, cert); file.MoveFile(fileoutput, fileinput); } #endregion } } catch (Exception ex) { throw ex; } }