Sample code for 30+ languages & platforms
SQL Server

Example: Crypt2.SetEncodedIV method

Demonstrates how to call the SetEncodedIV method.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @crypt int
    EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OASetProperty @crypt, 'CryptAlgorithm', 'aes'
    EXEC sp_OASetProperty @crypt, 'CipherMode', 'cbc'
    EXEC sp_OASetProperty @crypt, 'KeyLength', 256

    -- Note: The lenght of the IV is equal to the block size of the symmetric encryption algorithm.
    -- The block size for AES is 16 bytes.  Therefore, the IV is 16 bytes regardless of the encryption strenght (128-bit, 256-bit, etc.)
    EXEC sp_OAMethod @crypt, 'SetEncodedIV', NULL, '000102030405060708090A0B0C0D0E0F', 'hex'

    -- ...
    -- ...

    EXEC @hr = sp_OADestroy @crypt


END
GO