C# Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

C# Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
RSA Encryption
S/MIME
Socket
Spider
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
String
Byte Array
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

Create / Verify Detached Digital Signature for PDF using Chilkat Crypt

Download Chilkat .NET for 2.0 / 3.5 Framework

Download Chilkat .NET for 1.0 / 1.1 Framework

Creates a digital signature for a PDF file and then verifies the signature.

// Create/verify a detached signature for a PDF file.
private void SignPDF_Click(object sender, System.EventArgs e)
{
	Chilkat.Crypt crypt = new Chilkat.Crypt();

	// Get a 30-day trial code from http://www.chilkatsoft.com/register30.asp
	crypt.UnlockComponent("UnlockCode");

	// Read the PDF
	System.IO.FileInfo fInfo = new System.IO.FileInfo("sample.pdf");
	System.IO.BinaryReader br = new System.IO.BinaryReader(
		System.IO.File.OpenRead("sample.pdf"));
	byte [] pdfBytes = br.ReadBytes((int)fInfo.Length);
	br.Close();
	
	// Indicate which digital certificate is to be used.
	// This certificate must have the private key installed on the system.
	Chilkat.Cert cert = new Chilkat.Cert();
	// Replace this line with your own .cer or .p7b file.
	cert.LoadFromFile("matt.cer");
	crypt.SetSigningCertificate(cert);

	// Create the signature.
	byte [] signature = crypt.CreateSignature(pdfBytes);

	// Save the signature to a file.
	System.IO.BinaryWriter bw = new System.IO.BinaryWriter(
		System.IO.File.Create("signature.p7m"));
	bw.Write(signature);
	bw.Close();

	// Now load the signature back into another byte array.
	fInfo = new System.IO.FileInfo("signature.p7m");
	br = new System.IO.BinaryReader(
		System.IO.File.OpenRead("signature.p7m"));
	byte [] sigBytes = br.ReadBytes((int)fInfo.Length);
	br.Close();

	// This should be valid.
	bool valid1 = crypt.VerifySignature(pdfBytes,sigBytes);

	// Modify the data, and verify should return false.
	pdfBytes[0] = 0xCC;
	bool valid2 = crypt.VerifySignature(pdfBytes,sigBytes);

	MessageBox.Show("valid1 = " + valid1 + ", valid2 = " + valid2);
}

 

 

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Email Component · XML Parser