SQL Server
SQL Server
Load an EC Public Key from Point Coordinates
Demonstrates the Chilkat PublicKey.LoadEcdsa method, which loads an elliptic-curve public key from its affine point coordinates. The first argument names the curve, the second is the hexadecimal x-coordinate (Qx), and the third is the y-coordinate (Qy).
Background: An EC public key is a point (x, y) on a named curve, so this loader constructs the key from those raw values directly — the option to use when a system hands you the coordinates rather than an encoded key. The curve name (for example
secp256r1) is essential, since the same coordinates mean nothing without knowing which curve they lie on.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 PublicKey.LoadEcdsa method, which loads an elliptic-curve public key from its
-- affine point coordinates. The 1st argument names the curve, the 2nd is the hex x-coordinate
-- (Qx), and the 3rd is the hex y-coordinate (Qy).
DECLARE @pubKey int
EXEC @hr = sp_OACreate 'Chilkat.PublicKey', @pubKey OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @curveName nvarchar(4000)
SELECT @curveName = 'secp256r1'
DECLARE @qx nvarchar(4000)
SELECT @qx = '1ccbe91c075fc7f4f033bfa248db8fccd3565de94bbfb12f3c59ff46c271bf83'
DECLARE @qy nvarchar(4000)
SELECT @qy = 'ce4014c68811f9a21a1fdb2c0e6113e06db7ca93b7404e78dc7ccd5ca89a4ca9'
EXEC sp_OAMethod @pubKey, 'LoadEcdsa', @success OUT, @curveName, @qx, @qy
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @pubKey, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @pubKey
RETURN
END
PRINT 'Loaded an EC public key on ' + @curveName
EXEC @hr = sp_OADestroy @pubKey
END
GO