SQL Server
SQL Server
Load a Public Key from BinData
Demonstrates the Chilkat PublicKey.LoadBd method, which loads a public key from the bytes in a BinData. The only argument is the BinData, which may contain binary DER or any textual representation recognized by LoadFromString.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: When key bytes are already in memory — downloaded, extracted from a container, or pulled from a database — this loads them directly with no temporary file. It applies the same content inspection as the string and file loaders, so it accepts both binary DER and any recognized text form. It is the in-memory counterpart to
LoadFromFile.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the PublicKey.LoadBd method, which loads a public key from the bytes in a BinData.
-- The only argument is the BinData, which may contain binary DER or any textual representation
-- recognized by LoadFromString.
DECLARE @bd int
EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @bd, 'LoadFile', @success OUT, 'qa_data/public.der'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @bd, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @bd
RETURN
END
DECLARE @pubKey int
EXEC @hr = sp_OACreate 'Chilkat.PublicKey', @pubKey OUT
EXEC sp_OAMethod @pubKey, 'LoadBd', @success OUT, @bd
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @pubKey, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @bd
EXEC @hr = sp_OADestroy @pubKey
RETURN
END
EXEC sp_OAGetProperty @pubKey, 'KeyType', @sTmp0 OUT
PRINT 'Loaded a ' + @sTmp0 + ' public key.'
EXEC @hr = sp_OADestroy @bd
EXEC @hr = sp_OADestroy @pubKey
END
GO