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) Load a PuTTY Public KeyDemonstrates how to load a PuTTY public 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) -- Load a PuTTY public key. DECLARE @puttyKey int -- Use "Chilkat_9_5_0.SshKey" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.SshKey', @puttyKey OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @pubKeyText nvarchar(4000) EXEC sp_OAMethod @puttyKey, 'LoadText', @pubKeyText OUT, 'qa_data/ppk/putty_public.pem' -- The pubKeyText contains this content: -- ---- BEGIN SSH2 PUBLIC KEY ---- -- Comment: "rsa-key-20170126" -- AAAAB3NzaC1yc2EAAAABJQAAAQEAx+52s7vvaZ8rT2UdFZWlSUVDHDQ+5ZRFvgRW -- 6nm2sO1c9WqNg7u2PQL4jeKSDX2XWcMnpleALz2x8Rr4rMy5E1iZzvWov8VtFd8l -- fa9HOkgEeJB3VFuYR3NlnD3eyCoYJYPVpHJHrIeui2WZs5vQ76HDe+th8+z5Ald4 -- zPw3p2c6ZJpBrkSBM67hWokoBDi23c7NhszDHhJBrv+B98cQxnagI1PUKqN7E8Vg -- bNtBI8beIMHyI69up9G1AXSEi0cGIjYNx9RNUPau1mRk/SvfqxgWkAjM005lj7hc -- bOsjbdKK3T2NtrKTaYjEiXlEXcj1iGuApsD/m73pYaEJB3Nd7w== -- ---- END SSH2 PUBLIC KEY ---- DECLARE @success int EXEC sp_OAMethod @puttyKey, 'FromRfc4716PublicKey', @success OUT, @pubKeyText IF @success <> 1 BEGIN EXEC sp_OAGetProperty @puttyKey, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @puttyKey RETURN END -- If desired, convert to other public key formats: DECLARE @openSshPubKeyStr nvarchar(4000) EXEC sp_OAMethod @puttyKey, 'ToOpenSshPublicKey', @openSshPubKeyStr OUT PRINT @openSshPubKeyStr -- openSshPubKeyStr contains: -- ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAx+52s7vvaZ8rT2UdFZWlSUVDHDQ+5ZRFvgRW6nm2sO1c9WqNg7u2PQL4jeKSDX2XWcMnpleALz2x8Rr4rMy5E1iZzvWov8VtFd8lfa9HOkgEeJB3VFuYR3NlnD3eyCoYJYPVpHJHrIeui2WZs5vQ76HDe+th8+z5Ald4zPw3p2c6ZJpBrkSBM67hWokoBDi23c7NhszDHhJBrv+B98cQxnagI1PUKqN7E8VgbNtBI8beIMHyI69up9G1AXSEi0cGIjYNx9RNUPau1mRk/SvfqxgWkAjM005lj7hcbOsjbdKK3T2NtrKTaYjEiXlEXcj1iGuApsD/m73pYaEJB3Nd7w== rsa-key-20170126 -- Convert to an XML format: DECLARE @xmlPubKeyStr nvarchar(4000) EXEC sp_OAMethod @puttyKey, 'ToXml', @xmlPubKeyStr OUT PRINT @xmlPubKeyStr -- xmlPubKeyStr contains: -- <RSAPublicKey> -- <Modulus>x+52s7vvaZ8rT2UdFZWlSUVDHDQ+5ZRFvgRW6nm2sO1c9WqNg7u2PQL4jeKSDX2XWcMnpleALz2x8Rr4rMy5E1iZzvWov8VtFd8lfa9HOkgEeJB3VFuYR3NlnD3eyCoYJYPVpHJHrIeui2WZs5vQ76HDe+th8+z5Ald4zPw3p2c6ZJpBrkSBM67hWokoBDi23c7NhszDHhJBrv+B98cQxnagI1PUKqN7E8VgbNtBI8beIMHyI69up9G1AXSEi0cGIjYNx9RNUPau1mRk/SvfqxgWkAjM005lj7hcbOsjbdKK3T2NtrKTaYjEiXlEXcj1iGuApsD/m73pYaEJB3Nd7w==</Modulus> -- <Exponent>JQ==</Exponent> -- </RSAPublicKey> -- -- EXEC @hr = sp_OADestroy @puttyKey END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.