PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
string ls_Password
oleobject loo_Crypt
oleobject loo_Prng
oleobject loo_Bd
oleobject loo_Dt
string ls_Created
string ls_PasswordSha1
string ls_PasswordDigest
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
ls_Password = "secret"
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")
if li_rc < 0 then
destroy loo_Crypt
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Crypt.HashAlgorithm = "SHA-1"
loo_Crypt.EncodingMode = "base64"
// Generate a 16-byte random nonce
loo_Prng = create oleobject
li_rc = loo_Prng.ConnectToNewObject("Chilkat.Prng")
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")
loo_Prng.GenRandomBd(16,loo_Bd)
// Get the current date/time in a string with this format: 2010-06-08T07:26:50Z
loo_Dt = create oleobject
li_rc = loo_Dt.ConnectToNewObject("Chilkat.CkDateTime")
loo_Dt.SetFromCurrentSystemTime()
ls_Created = loo_Dt.GetAsTimestamp(0)
loo_Bd.AppendString(ls_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...
ls_PasswordSha1 = loo_Crypt.HashStringENC(ls_Password)
// Append the 20 binary bytes of the SHA1 hash to bd, which already contains the nonce and created date/time.
loo_Bd.AppendEncoded(ls_PasswordSha1,"base64")
ls_PasswordDigest = loo_Crypt.HashBdENC(loo_Bd)
Write-Debug "Base64 password digest = " + ls_PasswordDigest
destroy loo_Crypt
destroy loo_Prng
destroy loo_Bd
destroy loo_Dt