![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) secp256k1 Key Generation and Keccak-256See more ECC ExamplesStarting in v11.0.0, Chilkat supports both secp256k1 key generation and Keccak-256 directly. These algorithms are typically used for Bitcoin and Ethereum.Note: This example requires Chilkat v11.0.0 or greater.
integer li_rc oleobject loo_Fortuna string ls_Entropy integer li_Success oleobject loo_Ecc oleobject loo_PrivKey oleobject loo_Sb oleobject loo_Bd // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Create a Fortuna PRNG and seed it with system entropy. // This will be our source of random data for generating the ECDSA private key. loo_Fortuna = create oleobject // Use "Chilkat_9_5_0.Prng" for versions of Chilkat < 10.0.0 li_rc = loo_Fortuna.ConnectToNewObject("Chilkat.Prng") if li_rc < 0 then destroy loo_Fortuna MessageBox("Error","Connecting to COM object failed") return end if ls_Entropy = loo_Fortuna.GetEntropy(32,"base64") li_Success = loo_Fortuna.AddEntropy(ls_Entropy,"base64") loo_Ecc = create oleobject // Use "Chilkat_9_5_0.Ecc" for versions of Chilkat < 10.0.0 li_rc = loo_Ecc.ConnectToNewObject("Chilkat.Ecc") // Generate a random ECDSA private key on the secp256k1 curve. loo_PrivKey = loo_Ecc.GenEccKey("secp256k1",loo_Fortuna) if loo_Ecc.LastMethodSuccess <> 1 then Write-Debug loo_Ecc.LastErrorText destroy loo_Fortuna destroy loo_Ecc return end if Write-Debug "Successfully generated a sec256k1 key." destroy loo_PrivKey // Show how to compute the Keccak-256 hash in a few ways. loo_Sb = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder") loo_Sb.Append("hello") Write-Debug "keccak-256: " + loo_Sb.GetHash("keccak-256","hex_lower","utf-8") // Output: // keccak-256: 1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8 // To keccak-256 hash binary data loo_Bd = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData") loo_Bd.AppendEncoded("00010203040506","hex") Write-Debug "keccak-256: " + loo_Bd.GetHash("keccak-256","hex_lower") // Output: // keccak-256: 801560412425120fa609be232d6fa71c7f64f42aee7977267687dcc0a2f5aa63 destroy loo_Fortuna destroy loo_Ecc destroy loo_Sb destroy loo_Bd |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.