/*
* SecureBlackbox 2024 .NET Edition - Sample Project
*
* This sample project demonstrates the usage of SecureBlackbox in a
* simple, straightforward way. It is not intended to be a complete
* application. Error handling and other checks are simplified for clarity.
*
* www.nsoftware.com/secureblackbox
*
* This code is subject to the terms and conditions specified in the
* corresponding product license agreement which outlines the authorized
* usage and restrictions.
*
*/
using System;
using System.Windows.Forms;
using nsoftware.SecureBlackbox;
using System.IO;
namespace nsoftware.Demos
{
///
/// Summary description for frmMain.
///
public class xadessignerDemo : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lbXMLFile;
private System.Windows.Forms.TextBox edXMLFile;
private System.Windows.Forms.Button sbBrowseXMLFile;
private System.Windows.Forms.OpenFileDialog dlgOpen;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button btnSign;
private Button btnReferences;
private GroupBox gbKeyInfo;
public CheckBox cbIncludeKey;
private TextBox edKeyName;
private Label lbKeyName;
private TextBox edOutputFile;
private Button sbBrowseOutputFile;
private Label label2;
private ReferencesForm frmReferences;
private SaveFileDialog dlgSave;
public TextBox edTimestampServer;
public CheckBox cbTimestamp;
private Label lbVersion;
public ComboBox cmbVersion;
public CheckBox cbDetached;
private ComboBox cmbHashAlgorithm;
private Label lbSignatureMethod;
private ComboBox cmbCanonMethod;
private Label lbCanonMethod;
private Label label1;
public ComboBox cmbLevel;
private Label label3;
private Label label6;
private Button btnBrowseCert;
private TextBox edCertPassword;
private TextBox edSigningCertificate;
private Label lCertPassword;
private TextBox edSignatureLocation;
private Label lbSignatureLocation;
private XAdESSigner m_Signer;
private CertificateManager m_CertManager;
public xadessignerDemo()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
cmbCanonMethod.SelectedIndex = 0;
cmbHashAlgorithm.SelectedIndex = 2;
cmbVersion.SelectedIndex = 2;
cmbLevel.SelectedIndex = 1;
m_Signer = new XAdESSigner();
m_CertManager = new CertificateManager();
frmReferences = new ReferencesForm(m_Signer.References);
}
///
/// Clean up any resources being used.
///
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
m_Signer.Dispose();
m_CertManager.Dispose();
frmReferences.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.lbXMLFile = new System.Windows.Forms.Label();
this.edXMLFile = new System.Windows.Forms.TextBox();
this.sbBrowseXMLFile = new System.Windows.Forms.Button();
this.btnSign = new System.Windows.Forms.Button();
this.dlgOpen = new System.Windows.Forms.OpenFileDialog();
this.btnReferences = new System.Windows.Forms.Button();
this.gbKeyInfo = new System.Windows.Forms.GroupBox();
this.edSignatureLocation = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.lbSignatureLocation = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.cmbHashAlgorithm = new System.Windows.Forms.ComboBox();
this.cbDetached = new System.Windows.Forms.CheckBox();
this.lbSignatureMethod = new System.Windows.Forms.Label();
this.btnBrowseCert = new System.Windows.Forms.Button();
this.cmbCanonMethod = new System.Windows.Forms.ComboBox();
this.lbCanonMethod = new System.Windows.Forms.Label();
this.cmbLevel = new System.Windows.Forms.ComboBox();
this.edCertPassword = new System.Windows.Forms.TextBox();
this.edTimestampServer = new System.Windows.Forms.TextBox();
this.edSigningCertificate = new System.Windows.Forms.TextBox();
this.cbTimestamp = new System.Windows.Forms.CheckBox();
this.lCertPassword = new System.Windows.Forms.Label();
this.lbVersion = new System.Windows.Forms.Label();
this.cmbVersion = new System.Windows.Forms.ComboBox();
this.cbIncludeKey = new System.Windows.Forms.CheckBox();
this.edKeyName = new System.Windows.Forms.TextBox();
this.lbKeyName = new System.Windows.Forms.Label();
this.edOutputFile = new System.Windows.Forms.TextBox();
this.sbBrowseOutputFile = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.dlgSave = new System.Windows.Forms.SaveFileDialog();
this.label3 = new System.Windows.Forms.Label();
this.gbKeyInfo.SuspendLayout();
this.SuspendLayout();
//
// lbXMLFile
//
this.lbXMLFile.Location = new System.Drawing.Point(5, 38);
this.lbXMLFile.Name = "lbXMLFile";
this.lbXMLFile.Size = new System.Drawing.Size(60, 13);
this.lbXMLFile.TabIndex = 0;
this.lbXMLFile.Text = "Input file:";
//
// edXMLFile
//
this.edXMLFile.Location = new System.Drawing.Point(71, 35);
this.edXMLFile.Name = "edXMLFile";
this.edXMLFile.Size = new System.Drawing.Size(296, 20);
this.edXMLFile.TabIndex = 1;
//
// sbBrowseXMLFile
//
this.sbBrowseXMLFile.Location = new System.Drawing.Point(373, 32);
this.sbBrowseXMLFile.Name = "sbBrowseXMLFile";
this.sbBrowseXMLFile.Size = new System.Drawing.Size(75, 25);
this.sbBrowseXMLFile.TabIndex = 2;
this.sbBrowseXMLFile.Text = "Browse ...";
this.sbBrowseXMLFile.Click += new System.EventHandler(this.sbBrowseXMLFile_Click);
//
// btnSign
//
this.btnSign.Location = new System.Drawing.Point(588, 301);
this.btnSign.Name = "btnSign";
this.btnSign.Size = new System.Drawing.Size(75, 25);
this.btnSign.TabIndex = 9;
this.btnSign.Text = "Sign";
this.btnSign.Click += new System.EventHandler(this.btnSign_Click);
//
// btnReferences
//
this.btnReferences.Location = new System.Drawing.Point(8, 301);
this.btnReferences.Name = "btnReferences";
this.btnReferences.Size = new System.Drawing.Size(75, 25);
this.btnReferences.TabIndex = 8;
this.btnReferences.Text = "References";
this.btnReferences.Click += new System.EventHandler(this.btnReferences_Click);
//
// gbKeyInfo
//
this.gbKeyInfo.Controls.Add(this.edSignatureLocation);
this.gbKeyInfo.Controls.Add(this.label6);
this.gbKeyInfo.Controls.Add(this.lbSignatureLocation);
this.gbKeyInfo.Controls.Add(this.label1);
this.gbKeyInfo.Controls.Add(this.cmbHashAlgorithm);
this.gbKeyInfo.Controls.Add(this.cbDetached);
this.gbKeyInfo.Controls.Add(this.lbSignatureMethod);
this.gbKeyInfo.Controls.Add(this.btnBrowseCert);
this.gbKeyInfo.Controls.Add(this.cmbCanonMethod);
this.gbKeyInfo.Controls.Add(this.lbCanonMethod);
this.gbKeyInfo.Controls.Add(this.cmbLevel);
this.gbKeyInfo.Controls.Add(this.edCertPassword);
this.gbKeyInfo.Controls.Add(this.edTimestampServer);
this.gbKeyInfo.Controls.Add(this.edSigningCertificate);
this.gbKeyInfo.Controls.Add(this.cbTimestamp);
this.gbKeyInfo.Controls.Add(this.lCertPassword);
this.gbKeyInfo.Controls.Add(this.lbVersion);
this.gbKeyInfo.Controls.Add(this.cmbVersion);
this.gbKeyInfo.Controls.Add(this.cbIncludeKey);
this.gbKeyInfo.Controls.Add(this.edKeyName);
this.gbKeyInfo.Controls.Add(this.lbKeyName);
this.gbKeyInfo.Location = new System.Drawing.Point(8, 102);
this.gbKeyInfo.Name = "gbKeyInfo";
this.gbKeyInfo.Size = new System.Drawing.Size(655, 193);
this.gbKeyInfo.TabIndex = 5;
this.gbKeyInfo.TabStop = false;
this.gbKeyInfo.Text = "Signing options ";
//
// edSignatureLocation
//
this.edSignatureLocation.Location = new System.Drawing.Point(107, 161);
this.edSignatureLocation.Name = "edSignatureLocation";
this.edSignatureLocation.Size = new System.Drawing.Size(225, 20);
this.edSignatureLocation.TabIndex = 7;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(7, 22);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(94, 13);
this.label6.TabIndex = 65;
this.label6.Text = "Signing certificate:";
//
// lbSignatureLocation
//
this.lbSignatureLocation.AutoSize = true;
this.lbSignatureLocation.Location = new System.Drawing.Point(19, 164);
this.lbSignatureLocation.Name = "lbSignatureLocation";
this.lbSignatureLocation.Size = new System.Drawing.Size(82, 13);
this.lbSignatureLocation.TabIndex = 16;
this.lbSignatureLocation.Text = "Signature node:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(480, 48);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(33, 13);
this.label1.TabIndex = 19;
this.label1.Text = "Level:";
//
// cmbHashAlgorithm
//
this.cmbHashAlgorithm.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cmbHashAlgorithm.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbHashAlgorithm.Items.AddRange(new object[] {
"SHA1",
"MD5",
"SHA256",
"SHA384",
"SHA512",
"RIPEMD160"});
this.cmbHashAlgorithm.Location = new System.Drawing.Point(519, 99);
this.cmbHashAlgorithm.Name = "cmbHashAlgorithm";
this.cmbHashAlgorithm.Size = new System.Drawing.Size(125, 21);
this.cmbHashAlgorithm.TabIndex = 11;
//
// cbDetached
//
this.cbDetached.AutoSize = true;
this.cbDetached.Location = new System.Drawing.Point(10, 140);
this.cbDetached.Name = "cbDetached";
this.cbDetached.Size = new System.Drawing.Size(151, 17);
this.cbDetached.TabIndex = 6;
this.cbDetached.Text = "Create detached signature";
//
// lbSignatureMethod
//
this.lbSignatureMethod.AutoSize = true;
this.lbSignatureMethod.Location = new System.Drawing.Point(433, 102);
this.lbSignatureMethod.Name = "lbSignatureMethod";
this.lbSignatureMethod.Size = new System.Drawing.Size(80, 13);
this.lbSignatureMethod.TabIndex = 8;
this.lbSignatureMethod.Text = "Hash algorithm:";
//
// btnBrowseCert
//
this.btnBrowseCert.Location = new System.Drawing.Point(365, 16);
this.btnBrowseCert.Name = "btnBrowseCert";
this.btnBrowseCert.Size = new System.Drawing.Size(75, 25);
this.btnBrowseCert.TabIndex = 2;
this.btnBrowseCert.Text = "Browse ...";
this.btnBrowseCert.Click += new System.EventHandler(this.btnBrowseCert_Click);
//
// cmbCanonMethod
//
this.cmbCanonMethod.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cmbCanonMethod.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCanonMethod.Items.AddRange(new object[] {
"Canonical",
"Canonical with comments",
"Canonical v1.1",
"Canonical with comments v1.1",
"Exclusive canonical",
"Exclusive canonical with comments",
"Minimal canonical"});
this.cmbCanonMethod.Location = new System.Drawing.Point(519, 72);
this.cmbCanonMethod.Name = "cmbCanonMethod";
this.cmbCanonMethod.Size = new System.Drawing.Size(125, 21);
this.cmbCanonMethod.TabIndex = 10;
//
// lbCanonMethod
//
this.lbCanonMethod.AutoSize = true;
this.lbCanonMethod.Location = new System.Drawing.Point(426, 75);
this.lbCanonMethod.Name = "lbCanonMethod";
this.lbCanonMethod.Size = new System.Drawing.Size(87, 13);
this.lbCanonMethod.TabIndex = 2;
this.lbCanonMethod.Text = "Canonicalization:";
//
// cmbLevel
//
this.cmbLevel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cmbLevel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbLevel.Items.AddRange(new object[] {
"BaselineB",
"BaselineT",
"BaselineLT",
"BaselineLTA",
"BES",
"EPES",
"T",
"C",
"X",
"XType1",
"XType2",
"XL",
"XLType1",
"XLType2",
"A",
"ExtendedBES",
"ExtendedEPES",
"ExtendedT",
"ExtendedC",
"ExtendedX",
"ExtendedXType1",
"ExtendedXType2",
"ExtendedXLong",
"ExtendedXL",
"ExtendedXLType1",
"ExtendedXLType2 ",
"ExtendedA"});
this.cmbLevel.Location = new System.Drawing.Point(519, 45);
this.cmbLevel.Name = "cmbLevel";
this.cmbLevel.Size = new System.Drawing.Size(125, 21);
this.cmbLevel.TabIndex = 9;
//
// edCertPassword
//
this.edCertPassword.Location = new System.Drawing.Point(107, 45);
this.edCertPassword.Name = "edCertPassword";
this.edCertPassword.PasswordChar = '*';
this.edCertPassword.Size = new System.Drawing.Size(225, 20);
this.edCertPassword.TabIndex = 3;
//
// edTimestampServer
//
this.edTimestampServer.Location = new System.Drawing.Point(377, 161);
this.edTimestampServer.Name = "edTimestampServer";
this.edTimestampServer.Size = new System.Drawing.Size(267, 20);
this.edTimestampServer.TabIndex = 13;
this.edTimestampServer.Text = "http://";
//
// edSigningCertificate
//
this.edSigningCertificate.Location = new System.Drawing.Point(107, 19);
this.edSigningCertificate.Name = "edSigningCertificate";
this.edSigningCertificate.Size = new System.Drawing.Size(252, 20);
this.edSigningCertificate.TabIndex = 1;
//
// cbTimestamp
//
this.cbTimestamp.Location = new System.Drawing.Point(365, 143);
this.cbTimestamp.Name = "cbTimestamp";
this.cbTimestamp.Size = new System.Drawing.Size(244, 17);
this.cbTimestamp.TabIndex = 12;
this.cbTimestamp.Text = "Request a timestamp from TSA server:";
//
// lCertPassword
//
this.lCertPassword.AutoSize = true;
this.lCertPassword.Location = new System.Drawing.Point(45, 48);
this.lCertPassword.Name = "lCertPassword";
this.lCertPassword.Size = new System.Drawing.Size(56, 13);
this.lCertPassword.TabIndex = 61;
this.lCertPassword.Text = "Password:";
//
// lbVersion
//
this.lbVersion.AutoSize = true;
this.lbVersion.Location = new System.Drawing.Point(468, 22);
this.lbVersion.Name = "lbVersion";
this.lbVersion.Size = new System.Drawing.Size(45, 13);
this.lbVersion.TabIndex = 13;
this.lbVersion.Text = "Version:";
//
// cmbVersion
//
this.cmbVersion.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cmbVersion.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbVersion.Items.AddRange(new object[] {
"1.1.1",
"1.2.2",
"1.3.2",
"1.4.1"});
this.cmbVersion.Location = new System.Drawing.Point(519, 19);
this.cmbVersion.Name = "cmbVersion";
this.cmbVersion.Size = new System.Drawing.Size(125, 21);
this.cmbVersion.TabIndex = 8;
//
// cbIncludeKey
//
this.cbIncludeKey.Checked = true;
this.cbIncludeKey.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbIncludeKey.Location = new System.Drawing.Point(10, 80);
this.cbIncludeKey.Name = "cbIncludeKey";
this.cbIncludeKey.Size = new System.Drawing.Size(184, 24);
this.cbIncludeKey.TabIndex = 4;
this.cbIncludeKey.Text = "Include Key (public part)";
//
// edKeyName
//
this.edKeyName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.edKeyName.Location = new System.Drawing.Point(107, 106);
this.edKeyName.Name = "edKeyName";
this.edKeyName.Size = new System.Drawing.Size(225, 20);
this.edKeyName.TabIndex = 5;
//
// lbKeyName
//
this.lbKeyName.AutoSize = true;
this.lbKeyName.Location = new System.Drawing.Point(42, 109);
this.lbKeyName.Name = "lbKeyName";
this.lbKeyName.Size = new System.Drawing.Size(59, 13);
this.lbKeyName.TabIndex = 0;
this.lbKeyName.Text = "Key Name:";
//
// edOutputFile
//
this.edOutputFile.Location = new System.Drawing.Point(71, 65);
this.edOutputFile.Name = "edOutputFile";
this.edOutputFile.Size = new System.Drawing.Size(296, 20);
this.edOutputFile.TabIndex = 3;
//
// sbBrowseOutputFile
//
this.sbBrowseOutputFile.Location = new System.Drawing.Point(373, 62);
this.sbBrowseOutputFile.Name = "sbBrowseOutputFile";
this.sbBrowseOutputFile.Size = new System.Drawing.Size(75, 25);
this.sbBrowseOutputFile.TabIndex = 4;
this.sbBrowseOutputFile.Text = "Browse ...";
this.sbBrowseOutputFile.Click += new System.EventHandler(this.sbBrowseOutputFile_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(5, 68);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(60, 13);
this.label2.TabIndex = 18;
this.label2.Text = "Output file:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.ForeColor = System.Drawing.SystemColors.Highlight;
this.label3.Location = new System.Drawing.Point(5, 5);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(594, 13);
this.label3.TabIndex = 23;
this.label3.Text = "This sample shows how to create XAdES signatures. Please select an input file, tu" +
"ne up the signing options, and click \'Sign\'. ";
//
// xadessignerDemo
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(671, 337);
this.Controls.Add(this.label3);
this.Controls.Add(this.edOutputFile);
this.Controls.Add(this.sbBrowseOutputFile);
this.Controls.Add(this.label2);
this.Controls.Add(this.btnReferences);
this.Controls.Add(this.gbKeyInfo);
this.Controls.Add(this.edXMLFile);
this.Controls.Add(this.btnSign);
this.Controls.Add(this.sbBrowseXMLFile);
this.Controls.Add(this.lbXMLFile);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "xadessignerDemo";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "XAdES Signer Demo";
this.gbKeyInfo.ResumeLayout(false);
this.gbKeyInfo.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new xadessignerDemo());
}
private void sbBrowseXMLFile_Click(object sender, System.EventArgs e)
{
dlgOpen.Title = "";
dlgOpen.Filter = "XML file (*.xml)|*.XML";
if (dlgOpen.ShowDialog() == DialogResult.OK)
edXMLFile.Text = dlgOpen.FileName;
}
public Certificate LoadCertificate(string file, string password)
{
Certificate cert = null;
if (file.Length > 0)
{
try
{
m_CertManager.ImportFromFile(file, password);
cert = m_CertManager.Certificate;
}
catch (Exception ex)
{
MessageBox.Show("Failed to load certificate: " + ex.Message);
}
}
return cert;
}
private void btnSign_Click(object sender, System.EventArgs e)
{
m_Signer.OutputFile = edOutputFile.Text;
if (cbDetached.Checked)
{
m_Signer.DataFile = edXMLFile.Text;
m_Signer.DataURI = Path.GetFileName(edXMLFile.Text);
m_Signer.DataType = XAdESSignerDataTypes.cxdtBinary;
m_Signer.NewSignature.SignatureType = XMLSignatureTypes.cxstDetached;
}
else
{
m_Signer.InputFile = edXMLFile.Text;
m_Signer.NewSignature.SignatureType = XMLSignatureTypes.cxstEnveloped;
}
m_Signer.SigningCertificate = LoadCertificate(edSigningCertificate.Text, edCertPassword.Text);
switch (cmbCanonMethod.SelectedIndex)
{
case 0:
{
m_Signer.NewSignature.CanonicalizationMethod = XMLCanonicalizationMethods.cxcmCanon;
break;
}
case 1:
{
m_Signer.NewSignature.CanonicalizationMethod = XMLCanonicalizationMethods.cxcmCanonComment;
break;
}
case 2:
{
m_Signer.NewSignature.CanonicalizationMethod = XMLCanonicalizationMethods.cxcmCanon_v1_1;
break;
}
case 3:
{
m_Signer.NewSignature.CanonicalizationMethod = XMLCanonicalizationMethods.cxcmCanonComment_v1_1;
break;
}
case 4:
{
m_Signer.NewSignature.CanonicalizationMethod = XMLCanonicalizationMethods.cxcmExclCanon;
break;
}
case 5:
{
m_Signer.NewSignature.CanonicalizationMethod = XMLCanonicalizationMethods.cxcmExclCanonComment;
break;
}
case 6:
{
m_Signer.NewSignature.CanonicalizationMethod = XMLCanonicalizationMethods.cxcmMinCanon;
break;
}
default:
{
m_Signer.NewSignature.CanonicalizationMethod = XMLCanonicalizationMethods.cxcmCanon;
break;
}
}
m_Signer.NewSignature.HashAlgorithm = cmbHashAlgorithm.Text;
m_Signer.Config("KeyName=" + edKeyName.Text);
if (cbIncludeKey.Checked)
m_Signer.Config("IncludeKey=true");
else
m_Signer.Config("IncludeKey=false");
// Enable automatic signature formatting
m_Signer.Config("XMLFormatting=auto");
m_Signer.NewSignature.XMLElement = edSignatureLocation.Text;
// XAdES options
switch (cmbVersion.SelectedIndex)
{
case 0:
{
m_Signer.NewSignature.XAdESVersion = XAdESVersions.xav111;
break;
}
case 1:
{
m_Signer.NewSignature.XAdESVersion = XAdESVersions.xav122;
break;
}
case 3:
{
m_Signer.NewSignature.XAdESVersion = XAdESVersions.xav141;
break;
}
default:
{
m_Signer.NewSignature.XAdESVersion = XAdESVersions.xav132;
break;
}
}
m_Signer.NewSignature.Level = (AdESSignatureLevels)(cmbLevel.SelectedIndex + 2);
if (cbTimestamp.Checked)
{
m_Signer.TimestampServer = edTimestampServer.Text;
}
else
{
m_Signer.TimestampServer = "";
}
try
{
m_Signer.Sign();
MessageBox.Show("XML document successfully signed");
}
catch (Exception ex)
{
if (string.IsNullOrEmpty(m_Signer.NewSignature.ValidationLog))
MessageBox.Show(ex.Message);
else
MessageBox.Show(ex.Message + "\n\nUse XAdESSigner.ValidationLog property to obtain extended information about the error.");
}
}
private void btnReferences_Click(object sender, EventArgs e)
{
frmReferences.ShowDialog();
}
private string RequestPassword()
{
frmRequestPassword dlg = new frmRequestPassword();
string s = "";
if (dlg.ShowDialog() == DialogResult.OK)
{
s = dlg.tbInput.Text;
}
dlg.Dispose();
return s;
}
private void sbBrowseOutputFile_Click(object sender, EventArgs e)
{
dlgOpen.Filter = "";
if (dlgSave.ShowDialog() == DialogResult.OK)
edOutputFile.Text = dlgSave.FileName;
}
private void btnBrowseCert_Click(object sender, EventArgs e)
{
dlgOpen.Title = "Select certificate file";
dlgOpen.Filter = "PEM-encoded certificate (*.pem)|*.PEM|DER-encoded certificate (*.cer)|*.CER|PFX-encoded certificate (*.pfx)|*.PFX";
if (dlgOpen.ShowDialog() == DialogResult.OK)
edSigningCertificate.Text = dlgOpen.FileName;
}
}
}