Delphi DLL
Delphi DLL
Password_Digest = Base64 (SHA-1 ( nonce + created + SHA-1 (password) ) )
See more Encryption Examples
Demonstrates how to compute:Password_Digest = Base64 (SHA-1 ( nonce + created + SHA-1 (password)))
Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, BinData, Prng, CkDateTime, Crypt2;
...
procedure TForm1.Button1Click(Sender: TObject);
var
password: PWideChar;
crypt: HCkCrypt2;
prng: HCkPrng;
bd: HCkBinData;
dt: HCkDateTime;
created: PWideChar;
passwordSha1: PWideChar;
passwordDigest: PWideChar;
begin
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
password := 'secret';
crypt := CkCrypt2_Create();
CkCrypt2_putHashAlgorithm(crypt,'SHA-1');
CkCrypt2_putEncodingMode(crypt,'base64');
// Generate a 16-byte random nonce
prng := CkPrng_Create();
bd := CkBinData_Create();
CkPrng_GenRandomBd(prng,16,bd);
// Get the current date/time in a string with this format: 2010-06-08T07:26:50Z
dt := CkDateTime_Create();
CkDateTime_SetFromCurrentSystemTime(dt);
created := CkDateTime__getAsTimestamp(dt,False);
CkBinData_AppendString(bd,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...
passwordSha1 := CkCrypt2__hashStringENC(crypt,password);
// Append the 20 binary bytes of the SHA1 hash to bd, which already contains the nonce and created date/time.
CkBinData_AppendEncoded(bd,passwordSha1,'base64');
passwordDigest := CkCrypt2__hashBdENC(crypt,bd);
Memo1.Lines.Add('Base64 password digest = ' + passwordDigest);
CkCrypt2_Dispose(crypt);
CkPrng_Dispose(prng);
CkBinData_Dispose(bd);
CkDateTime_Dispose(dt);
end;