(SQL Server) MD4 Hash a String
MD4 hash a string.
-- 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 assumes 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
DECLARE @content nvarchar(4000)
SELECT @content = 'The quick brown fox jumps over the lazy dog'
-- The desired output is a hexidecimal string:
EXEC sp_OASetProperty @crypt, 'EncodingMode', 'hex'
-- Set the hash algorithm:
EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'md4'
DECLARE @hashStr nvarchar(4000)
EXEC sp_OAMethod @crypt, 'HashStringENC', @hashStr OUT, @content
PRINT @hashStr
-- The output is:
-- 1BEE69A46BA811185C194762ABAEAE9
EXEC @hr = sp_OADestroy @crypt
END
GO
|