SQL Server
SQL Server
Load a Private Key from XML Text
See more Private Key Examples
Demonstrates the Chilkat PrivateKey.LoadXml method, which loads a private key from XML text. The only argument is the XML string. Supported roots include RSAKeyValue, DSAKeyValue, ECCKeyValue, and Ed25519KeyValue.
Background: XML key representations such as
RSAKeyValue come from the .NET/XML-DSIG world, where keys are exchanged as XML elements. This loads that form — the inverse of GetXml — which is handy for interoperating with .NET code or systems built around XML signatures. It is a plaintext format, so protect the XML like any unencrypted key material.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the PrivateKey.LoadXml method, which loads a private key from XML text. The only
-- argument is the XML string. Supported roots include RSAKeyValue, DSAKeyValue, ECCKeyValue,
-- and Ed25519KeyValue.
DECLARE @privKey int
EXEC @hr = sp_OACreate 'Chilkat.PrivateKey', @privKey OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- The XML text of a private key (for example as produced by GetXml).
DECLARE @xmlText nvarchar(4000)
SELECT @xmlText = '<RSAKeyValue><Modulus>...</Modulus><Exponent>AQAB</Exponent>...</RSAKeyValue>'
EXEC sp_OAMethod @privKey, 'LoadXml', @success OUT, @xmlText
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @privKey, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @privKey
RETURN
END
EXEC sp_OAGetProperty @privKey, 'KeyType', @sTmp0 OUT
PRINT 'Loaded a ' + @sTmp0 + ' private key.'
EXEC @hr = sp_OADestroy @privKey
END
GO