Sample code for 30+ languages & platforms
SQL Server

Compute Glacier SHA256 Linear Hash of a File

See more Amazon Glacier Examples

Computes the Amazon Glacier SHA256 linear hash for a file.

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
    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @crypt int
    EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- The "linear hash" is simply the SHA256 hash of the file bytes.
    EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'sha256'

    -- Return the hash in lowercase hexidecimal format.
    EXEC sp_OASetProperty @crypt, 'EncodingMode', 'hexlower'

    DECLARE @linearHashHex nvarchar(4000)
    EXEC sp_OAMethod @crypt, 'HashFileENC', @linearHashHex OUT, 'qa_data/jpg/penguins.jpg'

    PRINT 'SHA256 linear hash = ' + @linearHashHex

    EXEC @hr = sp_OADestroy @crypt


END
GO