(SQL Server) Compute Glacier SHA256 Linear Hash of a File
Computes the Amazon Glacier SHA256 linear hash for a file.
-- 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
-- Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0
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
|