Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Generate RSA Key and return Base64 PKCS8 Private KeyDemonstrates how to generate a new 2048-bit RSA private key and returns the Base64 encoded PKCS8 representation of the private key.
-- 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 @rsa int -- Use "Chilkat_9_5_0.Rsa" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Rsa', @rsa OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int -- Generate a 2048-bit key. Chilkat RSA supports -- key sizes ranging from 512 bits to 8192 bits. EXEC sp_OAMethod @rsa, 'GenerateKey', @success OUT, 2048 IF @success <> 1 BEGIN EXEC sp_OAGetProperty @rsa, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @rsa RETURN END DECLARE @privKey int EXEC sp_OAMethod @rsa, 'ExportPrivateKeyObj', @privKey OUT -- Get the private key in PKCS8 Base64 format DECLARE @privKeyPkcs8Base64 nvarchar(4000) EXEC sp_OAMethod @privKey, 'GetPkcs8ENC', @privKeyPkcs8Base64 OUT, 'base64' -- The key in base64 format will start similar to this: -- MIIEvAIBADANBgkqhkiG9w0BA... PRINT @privKeyPkcs8Base64 EXEC @hr = sp_OADestroy @rsa END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.