Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3/4 Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(Node.js) RSA Sign Using Private Key from .pfx/.p12 to Base64 SignatureDemonstrates how to RSA sign something using a private key loaded from a .pfx/.p12. The RSA signature is returned in Base64 encoded format.
var os = require('os'); if (os.platform() == 'win32') { if (os.arch() == 'ia32') { var chilkat = require('@chilkat/ck-node11-win-ia32'); } else { var chilkat = require('@chilkat/ck-node11-win64'); } } else if (os.platform() == 'linux') { if (os.arch() == 'arm') { var chilkat = require('@chilkat/ck-node11-arm'); } else if (os.arch() == 'x86') { var chilkat = require('@chilkat/ck-node11-linux32'); } else { var chilkat = require('@chilkat/ck-node11-linux64'); } } else if (os.platform() == 'darwin') { var chilkat = require('@chilkat/ck-node11-macosx'); } function chilkatExample() { var rsa = new chilkat.Rsa(); // Any string argument automatically begins the 30-day trial. var success = rsa.UnlockComponent("30-day trial"); if (success !== true) { console.log(rsa.LastErrorText); return; } // Load the .pfx/.p12 var pfx = new chilkat.Pfx(); success = pfx.LoadPfxFile("qa_data/pfx/myKey.p12","myPassword"); if (success !== true) { console.log(pfx.LastErrorText); return; } // Get the default private key. // privKey: PrivateKey var privKey = pfx.GetPrivateKey(0); if (pfx.LastMethodSuccess !== true) { console.log(pfx.LastErrorText); return; } // Import the private key into the RSA component: success = rsa.ImportPrivateKeyObj(privKey); if (success !== true) { console.log(rsa.LastErrorText); return; } // This example will sign a string, and receive the signature // in a base64-encoded string. Therefore, set the encoding mode // to "base64": rsa.EncodingMode = "base64"; // If some other non-Chilkat application or web service is going to be verifying // the signature, it is important to match the byte-ordering. // The LittleEndian property may be set to true // for little-endian byte ordering, // or false for big-endian byte ordering. // Microsoft apps typically use little-endian, while // OpenSSL and other services (such as Amazon CloudFront) // use big-endian. rsa.LittleEndian = false; var strData = "This is the string to be signed."; // Sign the string using the sha-256 hash algorithm. // Other valid choices are "sha-1", "md2" and "md5". var base64Sig = rsa.SignStringENC(strData,"sha-256"); console.log(base64Sig); console.log("Success!"); } chilkatExample(); |
© 2000-2016 Chilkat Software, Inc. All Rights Reserved.