C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CUnicode C++Unicode CMFCDelphi DLLDelphi ActiveXFoxProJavaPerlPHP 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

 

 

 

 

 

 

Decrypt a .p7m (PKCS7) File

Download: Chilkat .NET Assemblies

C# example to decrypt a .p7m. You must have the required digital certificate installed (with private key) on your system in order to decrypt.

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

//  Any string argument automatically begins the 30-day trial.
bool success;
success = crypt.UnlockComponent("30-day trial");
if (success != true) {
    MessageBox.Show("Crypt component unlock failed");
    return;
}

crypt.CryptAlgorithm = "pki";

//  To decrypt in memory:
//  
byte[] p7mData = crypt.ReadFile("test.p7m");

byte [] decrypted = crypt.DecryptBytes(p7mData);

string decryptedStr = System.Text.Encoding.ASCII.GetString(decrypted);

textBox1.Text = decryptedStr;

//  To decrypt you'll need the private key.
//  Also, the certificate should have already been installed
//  on the computer.  This is typically achieved by installing
//  from a .pfx file, or by importing from a certificate
//  authority's online web application.  If you are decrypting
//  from ASP, ASP.NET, or a Windows Service, you'll need to
//  import in a way that provides the calling process permission
//  to access and use the private key.  The procedure for
//  doing this is explained here:
//  http://blog.chilkatsoft.com/?p=149
//  Also, there is no "SetDecryptCert" method.  The .p7m
//  contains information that allows the Chilkat component
//  to locate the certificate to be used for decryption.
//  The Chilkat Crypt component automatically searches
//  the Windows Current User certificate store and the
//  Local Machine certificate store.

//  For file-to-file decryption:
success = crypt.CkDecryptFile("dude.p7m","dudeOut.gif");
if (success != true) {
    MessageBox.Show(crypt.LastErrorText);
    return;
}


 

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