SQL Server
SQL Server
Provide a Certificate Vault to an Email
See more Email Object Examples
Demonstrates the Chilkat Email.UseCertVault method, which adds an XML certificate vault to the email's internal certificate and private-key lookup sources for encryption, decryption, signing, and verification. This example builds a vault from a PFX and attaches it to the email.
Background: A certificate vault is a portable, in-memory store of certificates and private keys. Instead of wiring up each certificate individually for every operation, you load your credentials into one
XmlCertVault and hand it to the email; Chilkat then draws on it automatically whenever it needs a key — to decrypt an incoming message, sign an outgoing one, or verify a signature. This is especially convenient on platforms without an OS certificate store.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the UseCertVault method, which adds an XML certificate vault to the email's
-- internal certificate and private-key lookup sources for encryption, decryption, signing,
-- and verification.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Build a certificate vault from a PFX (certificate + private key).
DECLARE @vault int
EXEC @hr = sp_OACreate 'Chilkat.XmlCertVault', @vault OUT
EXEC sp_OAMethod @vault, 'AddPfxFile', @success OUT, 'qa_data/certs/certs.pfx', 'pfx_password'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @vault, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @vault
RETURN
END
-- Make the vault available to the email object for crypto operations.
EXEC sp_OAMethod @email, 'UseCertVault', @success OUT, @vault
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @vault
RETURN
END
PRINT 'Certificate vault attached to the email.'
-- Note: The path "qa_data/certs/certs.pfx" is a relative local filesystem path,
-- relative to the current working directory of the running application.
EXEC @hr = sp_OADestroy @email
EXEC @hr = sp_OADestroy @vault
END
GO