Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Create PKCS7 Signature using .cer and .key FilesUses 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... Dim cert As New Chilkat.Cert() Dim success As Boolean success = cert.LoadFromFile("myCert.cer") If (success <> true) Then TextBox1.Text = TextBox1.Text & cert.LastErrorText & vbCrLf Exit Sub End If Dim privKey As New Chilkat.PrivateKey() Dim password As String 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) Then TextBox1.Text = TextBox1.Text & privKey.LastErrorText & vbCrLf Exit Sub End If ' NOTE: In this example, the .cer should contain the public key ' that corresponds to the private key. Dim crypt As New Chilkat.Crypt2() ' Any string argument automatically begins the 30-day trial. success = crypt.UnlockComponent("30-day trial") If (success <> true) Then TextBox1.Text = TextBox1.Text & crypt.LastErrorText & vbCrLf Exit Sub End If ' Set the certifcate + private key to be used for signing: crypt.SetSigningCert2(cert,privKey) Dim pkcs7Sig() As Byte Dim textToSign As String textToSign = "This is the text to be signed." pkcs7Sig = crypt.SignString(textToSign) If (pkcs7Sig.Length = 0 ) Then TextBox1.Text = TextBox1.Text & crypt.LastErrorText & vbCrLf Exit Sub End If ' Save the PKCS7 signature to a file. System.IO.File.WriteAllBytes("sig.p7s", pkcs7Sig) |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.