SQL Server
SQL Server
Cache a DKIM Public Key from a File
See more DKIM / DomainKey Examples
Demonstrates the Chilkat Dkim.LoadPublicKeyFile method, which caches an RSA public key read from a local file for a specific selector and domain. The arguments are the selector, the domain, and the public-key file path. Supported formats include PEM X.509 SubjectPublicKeyInfo and PEM PKCS#1 RSA public key.
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: This is the file-based form of
LoadPublicKey, convenient when the key already lives in a .pem file — a saved copy of what the domain publishes in DNS. As with the string form, the cache is keyed on the exact selector and domain, so those must match the signature being verified. Pre-loading keys this way lets a verifier work without any DNS access at all.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the Dkim.LoadPublicKeyFile method, which caches an RSA public key read from a
-- local file for a specific selector and domain. The 1st argument is the selector, the 2nd is
-- the domain, and the 3rd is the local public-key file path.
DECLARE @dkim int
EXEC @hr = sp_OACreate 'Chilkat.Dkim', @dkim OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Read the public key from a file and cache it under the exact selector and domain. Supported
-- formats include PEM X.509 SubjectPublicKeyInfo and PEM PKCS#1 RSA public key.
EXEC sp_OAMethod @dkim, 'LoadPublicKeyFile', @success OUT, 'myselector', 'example.com', 'qa_data/dkim_public.pem'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @dkim, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @dkim
RETURN
END
PRINT 'Public key loaded and cached.'
EXEC @hr = sp_OADestroy @dkim
END
GO