Visual Basic Examples

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

VB Examples

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

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
DH Key Exchange
DSA
FileAccess
RSS
Atom
Self-Extractor
Service
Bzip2
PPMD
Deflate
LZW


VB Strings
VB Byte Array

 

 

 

 

 

 

 

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 FileAccess ActiveX (freeware)

Download Chilkat Crypt ActiveX

'  First, load the .cer and .key files into Chilkat objects...
Dim cert As New ChilkatCert

Dim success As Long
success = cert.LoadFromFile("myCert.cer")
If (success <> 1) Then
    Text1.Text = Text1.Text & cert.LastErrorText & vbCrLf
    Exit Sub
End If

Dim privKey As New 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 <> 1) Then
    Text1.Text = Text1.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 ChilkatCrypt2

'  Any string argument automatically begins the 30-day trial.
success = crypt.UnlockComponent("30-day trial")
If (success <> 1) Then
    Text1.Text = Text1.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 ( UBound(pkcs7Sig) = -1 ) Then
    Text1.Text = Text1.Text & crypt.LastErrorText & vbCrLf
    Exit Sub
End If

'  Save the PKCS7 signature to a file.
Dim fac As New CkFileAccess
Dim facSuccess As Long
facSuccess = fac.WriteEntireFile("sig.p7s", pkcs7Sig)
If (facSuccess = 0) Then
    MsgBox fac.LastErrorText
    Exit Sub
End If

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