![]() |
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
(SQL Server) 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.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @success int SELECT @success = 0 -- This example assumes the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @privKey int EXEC @hr = sp_OACreate 'Chilkat.PrivateKey', @privKey OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Load the private key from an RSA PEM file: EXEC sp_OAMethod @privKey, 'LoadPemFile', @success OUT, 'private.pem' IF @success = 0 BEGIN EXEC sp_OAGetProperty @privKey, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @privKey RETURN END DECLARE @rsa int EXEC @hr = sp_OACreate 'Chilkat.Rsa', @rsa OUT EXEC sp_OAMethod @rsa, 'UsePrivateKey', @success OUT, @privKey IF @success = 0 BEGIN EXEC sp_OAGetProperty @rsa, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @rsa RETURN END DECLARE @strData nvarchar(4000) SELECT @strData = 'secret' DECLARE @bd int EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT EXEC sp_OAMethod @bd, 'AppendString', @success OUT, @strData, 'utf-8' EXEC sp_OAMethod @rsa, 'SignRawBd', @success OUT, @bd DECLARE @hexSig nvarchar(4000) EXEC sp_OAMethod @bd, 'GetEncoded', @hexSig OUT, 'hex' PRINT @hexSig -- Recover the data using the corresponding public key: DECLARE @pubKey int EXEC @hr = sp_OACreate 'Chilkat.PublicKey', @pubKey OUT -- Load the public key from a PEM file: EXEC sp_OAMethod @pubKey, 'LoadFromFile', @success OUT, 'public.pem' IF @success = 0 BEGIN EXEC sp_OAGetProperty @pubKey, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @rsa EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @pubKey RETURN END DECLARE @rsa2 int EXEC @hr = sp_OACreate 'Chilkat.Rsa', @rsa2 OUT EXEC sp_OAMethod @rsa2, 'UsePublicKey', @success OUT, @pubKey IF @success = 0 BEGIN EXEC sp_OAGetProperty @rsa2, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @rsa EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @pubKey EXEC @hr = sp_OADestroy @rsa2 RETURN END DECLARE @bd2 int EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd2 OUT EXEC sp_OAMethod @bd2, 'AppendEncoded', @success OUT, @hexSig, 'hex' -- Recover the original data. EXEC sp_OAMethod @rsa2, 'VerifyRawBd', @success OUT, @bd2 IF @success = 0 BEGIN EXEC sp_OAGetProperty @rsa2, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @rsa EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @pubKey EXEC @hr = sp_OADestroy @rsa2 EXEC @hr = sp_OADestroy @bd2 RETURN END DECLARE @originalData nvarchar(4000) EXEC sp_OAMethod @bd2, 'GetString', @originalData OUT, 'utf-8' PRINT @originalData EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @rsa EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @pubKey EXEC @hr = sp_OADestroy @rsa2 EXEC @hr = sp_OADestroy @bd2 END GO |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.