(SQL Server) Generate Salt in Hex or Base64 Format
      
      Demonstrates how to generate a cryptographic salt value and get the result as hex or base64. 
		
 
      -- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- In cryptography, a salt is random data that is used as an additional input to a one-way function that "hashes" data, a password or passphrase.
    -- Let's say we want to generate a 16-byte salt value..
    DECLARE @prng int
    -- Use "Chilkat_9_5_0.Prng" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Prng', @prng OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END
    DECLARE @saltHex nvarchar(4000)
    EXEC sp_OAMethod @prng, 'GenRandom', @saltHex OUT, 16, 'hex'
    PRINT '16-byte salt as hex: ' + @saltHex
    DECLARE @saltBase64 nvarchar(4000)
    EXEC sp_OAMethod @prng, 'GenRandom', @saltBase64 OUT, 16, 'base64'
    PRINT '16-byte salt as base64: ' + @saltBase64
    EXEC @hr = sp_OADestroy @prng
END
GO
     |