Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Password_Digest = Base64 (SHA-1 ( nonce + created + SHA-1 (password) ) )Demonstrates how to compute: Password_Digest = Base64 (SHA-1 ( nonce + created + SHA-1 (password)))
-- 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 @password nvarchar(4000) SELECT @password = 'secret' 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 EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'SHA-1' EXEC sp_OASetProperty @crypt, 'EncodingMode', 'base64' -- Generate a 16-byte random nonce DECLARE @prng int -- Use "Chilkat_9_5_0.Prng" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Prng', @prng OUT DECLARE @bd int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT DECLARE @success int EXEC sp_OAMethod @prng, 'GenRandomBd', @success OUT, 16, @bd -- Get the current date/time in a string with this format: 2010-06-08T07:26:50Z DECLARE @dt int -- Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @dt OUT EXEC sp_OAMethod @dt, 'SetFromCurrentSystemTime', @success OUT DECLARE @created nvarchar(4000) EXEC sp_OAMethod @dt, 'GetAsTimestamp', @created OUT, 0 EXEC sp_OAMethod @bd, 'AppendString', @success OUT, @created, 'utf-8' -- This example wishes to calculate a password digest like this: -- Password_Digest = Base64 ( SHA-1 ( nonce + created + SHA-1(password) ) ) -- First SHA-1 digest the password... DECLARE @passwordSha1 nvarchar(4000) EXEC sp_OAMethod @crypt, 'HashStringENC', @passwordSha1 OUT, @password -- Append the 20 binary bytes of the SHA1 hash to bd, which already contains the nonce and created date/time. EXEC sp_OAMethod @bd, 'AppendEncoded', @success OUT, @passwordSha1, 'base64' DECLARE @passwordDigest nvarchar(4000) EXEC sp_OAMethod @crypt, 'HashBdENC', @passwordDigest OUT, @bd PRINT 'Base64 password digest = ' + @passwordDigest EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @prng EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @dt END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.