SQL Server
SQL Server
Set the OAEP Hash Algorithm for Encrypted Email
See more Email Object Examples
Demonstrates the Chilkat Email.OaepHash property, which selects the hash algorithm used by OAEP padding when encrypting email with RSAES-OAEP. Valid values are sha1, sha256, sha384, and sha512; the default is sha256. This property is used only when OaepPadding is true, so this example enables OAEP first.
Background: OAEP ("Optimal Asymmetric Encryption Padding") uses a hash function internally as part of the randomized padding it wraps around the data before RSA encryption. The choice of hash affects security and, importantly, interoperability: the sender and recipient must use the same OAEP hash, or decryption fails. That is why this is exposed as an explicit setting rather than left implicit.
Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
-- Demonstrates the Email.OaepHash property, which selects the hash algorithm used by
-- OAEP padding when encrypting email with RSAES-OAEP. Valid values: sha1, sha256,
-- sha384, sha512. The default is sha256. It is used only when OaepPadding is true.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @email, 'Subject', 'Encrypted with RSAES-OAEP'
-- OAEP padding must be enabled for the OAEP hash to take effect.
EXEC sp_OASetProperty @email, 'OaepPadding', 1
EXEC sp_OASetProperty @email, 'OaepHash', 'sha256'
EXEC sp_OAGetProperty @email, 'OaepHash', @sTmp0 OUT
PRINT 'OaepHash = ' + @sTmp0
EXEC @hr = sp_OADestroy @email
END
GO