Sample code for 30+ languages & platforms
SQL Server

MD4 Hash a String

See more Encryption Examples

MD4 hash a string.

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 assumes 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

    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