Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicPythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcel

Perl Examples


ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)

Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
VoiceBase
Walmart
WebSocket
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Perl) Get RSA Key Modulus from .cer or .key

Demonstrates how to get the RSA key modulus from either the certificate (.cer) or RSA key (.key). OpenSSL commands to do the same would be:

openssl x509 -inform DER -in "test.cer"  -modulus -noout 
or
openssl pkcs8 -inform DER -in​ "test.key"​ -outform PEM -passin pass:"12345​678a​"
   | openssl rsa -inform PEM -modulus -noout 

Chilkat Perl Downloads

Perl Module for Windows, Linux, MAC OS X, Solaris, and FreeBSD

use chilkat();

$privKey = chilkat::CkPrivateKey->new();

$password = "12345678a";
$success = $privKey->LoadPkcs8EncryptedFile("qa_data/certs/test_12345678a.key",$password);
if ($success != 1) {
    print $privKey->lastErrorText() . "\r\n";
    exit;
}

$xml = chilkat::CkXml->new();
$xml->LoadXml($privKey->getXml());

#  The XML contains the parts of the key in base64.
print "Private Key XML:" . "\r\n";
print $xml->getXml() . "\r\n";

#  We can get the base64 modulus like this:
$modulus = $xml->getChildContent("Modulus");
print "base64 modulus = " . $modulus . "\r\n";

#  To convert to hex:
$binDat = chilkat::CkBinData->new();
$binDat->AppendEncoded($modulus,"base64");
$hexModulus = $binDat->getEncoded("hex");
print "hex modulus = " . $hexModulus . "\r\n";

#  Now get the modulus from the cert:
$cert = chilkat::CkCert->new();

$success = $cert->LoadFromFile("qa_data/certs/test_12345678a.cer");
if ($success != 1) {
    print $cert->lastErrorText() . "\r\n";
    exit;
}

#  The cert contains the public key, which is composed of the
#  modulus + exponent (for RSA keys).
# pubKey is a PublicKey
$pubKey = $cert->ExportPublicKey();

$xml->LoadXml($pubKey->getXml());
print "Public Key XML:" . "\r\n";
print $xml->getXml() . "\r\n";

#  Proceed in the same way as before....
$modulus = $xml->getChildContent("Modulus");
print "base64 modulus = " . $modulus . "\r\n";

#  To convert to hex:
$binDat->Clear();
$binDat->AppendEncoded($modulus,"base64");
$hexModulus = $binDat->getEncoded("hex");
print "hex modulus = " . $hexModulus . "\r\n";


 

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