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) Generate an RSA Key and Export to XMLSee more RSA ExamplesDemonstrates how to generate an RSA key and export public/private to XML.
-- 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 -- Generate a 2048-bit key. DECLARE @success int EXEC sp_OAMethod @rsa, 'GenerateKey', @success OUT, 2048 IF @success = 0 BEGIN EXEC sp_OAGetProperty @rsa, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @rsa RETURN END DECLARE @privKeyXml nvarchar(4000) EXEC sp_OAMethod @rsa, 'ExportPrivateKey', @privKeyXml OUT PRINT @privKeyXml -- Sample output: -- <RSAKeyValue> -- <Modulus>pvxYRzbV8Gru5/NNFQunXkLfhUW9W83/A+LtVD5jhV5oDZ5mv9R3BbfBE88UTqGjA1jZoFegprY3dGpm7Dl0PFqIYSwfE869Tx7OGzg+ocsM3klTBslxVftN4grJzovfWeUbi22JNbOEjuvI9548OmTnIHhYI9yhl54xyIHUIRWCa6nlPNfqqFD/tscmel+2AwWM5hhylse2Q3xg1Y3D3al3BckGGvrBGjKAFoN60+kmD0mnisy0zfHRAiHH8EsqSXASXjqRa6G60jj+tRrdY5AcOrtWe7tsoHE8txGI+xZQ6g3MWelyNM6Dnb324hid8rNxj33lFiqbOkQGPvE9fw==</Modulus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EJ0umlWqcFqY3mmtg50VVPhbqons=</DQ> -- <InverseQ>W7bC5ZD55dv6XqmfHDVuUoI8IZQVnM1M1BtA5+tTFXxPT29ZUov7wOh+5R2nygUqkJfiNAC0s18tPiv7HoQXHxIskI2tXT3XM9yJdZOnAXCzV+xh+zeenBVTD63PvpNpC9Obrxd1rpBi2jTIFESgD0Cn5CKEIUpXIGntaNLLgDI=</InverseQ> -- </RSAKeyValue> DECLARE @pubKeyXml nvarchar(4000) EXEC sp_OAMethod @rsa, 'ExportPublicKey', @pubKeyXml OUT PRINT @pubKeyXml -- Sample output: -- <RSAPublicKey> -- <Modulus>pvxYRzbV8Gru5/NNFQunXkLfhUW9W83/A+LtVD5jhV5oDZ5mv9R3BbfBE88UTqGjA1jZoFegprY3dGpm7Dl0PFqIYSwfE869Tx7OGzg+ocsM3klTBslxVftN4grJzovfWeUbi22JNbOEjuvI9548OmTnIHhYI9yhl54xyIHUIRWCa6nlPNfqqFD/tscmel+2AwWM5hhylse2Q3xg1Y3D3al3BckGGvrBGjKAFoN60+kmD0mnisy0zfHRAiHH8EsqSXASXjqRa6G60jj+tRrdY5AcOrtWe7tsoHE8txGI+xZQ6g3MWelyNM6Dnb324hid8rNxj33lFiqbOkQGPvE9fw==</Modulus> -- <Exponent>AQAB</Exponent> -- </RSAPublicKey> EXEC @hr = sp_OADestroy @rsa END GO |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.