C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C# Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

Create PKCS7 Signature using .cer and .key Files

Uses a digital certificate (.cer file) and private key file to create a PKCS7 signature.

Download: Chilkat .NET Assemblies

//  First, load the .cer and .key files into Chilkat objects...
Chilkat.Cert cert = new Chilkat.Cert();

bool success;
success = cert.LoadFromFile("myCert.cer");
if (success != true) {
    textBox1.Text += cert.LastErrorText + "\r\n";
    return;
}

Chilkat.PrivateKey privKey = new Chilkat.PrivateKey();
string password;
password = "myPassword";
//  The private key object provides different methods for
//  loading keys of many different formats.
//  This example loads a PKCS8 encrypted private key.
success = privKey.LoadPkcs8EncryptedFile("myPrivateKey.key",password);
if (success != true) {
    textBox1.Text += privKey.LastErrorText + "\r\n";
    return;
}

//  NOTE:  In this example, the .cer should contain the public key
//  that corresponds to the private key.

Chilkat.Crypt2 crypt = new Chilkat.Crypt2();

//  Any string argument automatically begins the 30-day trial.
success = crypt.UnlockComponent("30-day trial");
if (success != true) {
    textBox1.Text += crypt.LastErrorText + "\r\n";
    return;
}

//  Set the certifcate + private key to be used for signing:
crypt.SetSigningCert2(cert,privKey);

byte[] pkcs7Sig = null;

string textToSign;
textToSign = "This is the text to be signed.";
pkcs7Sig = crypt.SignString(textToSign);
if (pkcs7Sig.Length == 0 ) {
    textBox1.Text += crypt.LastErrorText + "\r\n";
    return;
}

//  Save the PKCS7 signature to a file.
System.IO.File.WriteAllBytes("sig.p7s", pkcs7Sig);

 

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

Email Component · XML Parser