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. Downloads for Windows/Linux and Install Instructions require 'rubygems' require 'chilkat' # First, load the .cer and .key files into Chilkat objects... cert = Chilkat::CkCert.new() success = cert.LoadFromFile("myCert.cer") if (success != true) print cert.lastErrorText() + "\n"; exit end privKey = Chilkat::CkPrivateKey.new() 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) print privKey.lastErrorText() + "\n"; exit end # NOTE: In this example, the .cer should contain the public key # that corresponds to the private key. crypt = Chilkat::CkCrypt2.new() # Any string argument automatically begins the 30-day trial. success = crypt.UnlockComponent("30-day trial") if (success != true) print crypt.lastErrorText() + "\n"; exit end # Set the certifcate + private key to be used for signing: crypt.SetSigningCert2(cert,privKey) pkcs7 = Chilkat::CkByteData.new() textToSign = "This is the text to be signed." success = crypt.SignString(textToSign,pkcs7) if (success == false) print crypt.lastErrorText() + "\n"; exit end # Save the PKCS7 signature to a file. success = pkcs7.saveFile("out_pkcs7.p7s") if (success == false) print "Failed to save output file." + "\n" else print "Success." + "\n" end |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.