![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Java) Duplicating OpenSSL rsautl (creating RSA signatures)Demonstrates how to duplicate OpenSSL rsautil RSA signatures. The Chilkat RSA component's methods for creating RSA signatures (SignBytes, SignBytesENC, SignString, and SignStringENC) are very different from OpenSSL's rsautl command. First, we'll explain what Chilkat's signing methods do, and then what OpenSSL's rsautl does. New signing methods have been added to Chilkat RSA to duplicate OpenSSL rsautl: OpenSslSignBytes, OpenSslSignBytesENC, OpenSslSignString, and OpenSslSignStringENC.
Here's what Chilkat's RSA Sign* methods do:
OpenSSL rsautl is very different. Here's what it does:
Note: This example requires Chilkat v11.0.0 or greater.
import com.chilkatsoft.*; public class ChilkatExample { static { try { System.loadLibrary("chilkat"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load.\n" + e); System.exit(1); } } public static void main(String argv[]) { boolean success = false; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkPrivateKey privKey = new CkPrivateKey(); // Load the private key from an RSA PEM file: success = privKey.LoadPemFile("private.pem"); if (success == false) { System.out.println(privKey.lastErrorText()); return; } CkRsa rsa = new CkRsa(); success = rsa.UsePrivateKey(privKey); if (success == false) { System.out.println(rsa.lastErrorText()); return; } String strData = "secret"; CkBinData bd = new CkBinData(); bd.AppendString(strData,"utf-8"); success = rsa.SignRawBd(bd); String hexSig = bd.getEncoded("hex"); System.out.println(hexSig); // Recover the data using the corresponding public key: CkPublicKey pubKey = new CkPublicKey(); // Load the public key from a PEM file: success = pubKey.LoadFromFile("public.pem"); if (success == false) { System.out.println(pubKey.lastErrorText()); return; } CkRsa rsa2 = new CkRsa(); success = rsa2.UsePublicKey(pubKey); if (success == false) { System.out.println(rsa2.lastErrorText()); return; } CkBinData bd2 = new CkBinData(); bd2.AppendEncoded(hexSig,"hex"); // Recover the original data. success = rsa2.VerifyRawBd(bd2); if (success == false) { System.out.println(rsa2.lastErrorText()); return; } String originalData = bd2.getString("utf-8"); System.out.println(originalData); } } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.