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
(PowerBuilder) Create JCEKS Containing Secret KeysDemonstrates how to create a JCEKS keystore file containing symmetric secret keys (for AES, Blowfish, HMAC SHA25, ChaCha20, etc.) This example requires Chilkat v9.5.0.66 or greater.
integer li_rc oleobject loo_Jceks oleobject loo_Prng string ls_AesKey string ls_BlowfishKey string ls_HmacKey string ls_ChachaKey string ls_Encoding string ls_Password string ls_FilePassword integer li_Success oleobject loo_SbJson oleobject loo_Json // IMPORTANT: This example requires Chilkat v9.5.0.66 or greater. // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Jceks = create oleobject // Use "Chilkat_9_5_0.JavaKeyStore" for versions of Chilkat < 10.0.0 li_rc = loo_Jceks.ConnectToNewObject("Chilkat.JavaKeyStore") if li_rc < 0 then destroy loo_Jceks MessageBox("Error","Connecting to COM object failed") return end if // We'll need a pseudo-random number generator (PRNG) to generate symmetric keys. loo_Prng = create oleobject // Use "Chilkat_9_5_0.Prng" for versions of Chilkat < 10.0.0 li_rc = loo_Prng.ConnectToNewObject("Chilkat.Prng") // Generate some keys.. // 128-bit AES key (16 bytes) ls_AesKey = loo_Prng.GenRandom(16,"base64") // 256-bit Blowfish key (32 bytes) ls_BlowfishKey = loo_Prng.GenRandom(32,"base64") // HMAC SHA256 key // (An HMAC key can be anything, and any length. We'll use the following string: ls_HmacKey = "This is my HMAC key" // ChaCha20 256-bit ls_ChachaKey = loo_Prng.GenRandom(32,"base64") // Add each secret key to the JCEKS ls_Encoding = "base64" ls_Password = "secret" loo_Jceks.AddSecretKey(ls_AesKey,ls_Encoding,"AES","my aes key",ls_Password) loo_Jceks.AddSecretKey(ls_BlowfishKey,ls_Encoding,"BLOWFISH","my blowfish key",ls_Password) // For HMAC, we're using the us-ascii bytes for the key.. loo_Jceks.AddSecretKey(ls_HmacKey,"ascii","HMAC_SHA256","my hmac key",ls_Password) loo_Jceks.AddSecretKey(ls_ChachaKey,ls_Encoding,"CHACHA","my chacha20 key",ls_Password) ls_FilePassword = "password" // Write the JCEKs to a file. li_Success = loo_Jceks.ToFile(ls_FilePassword,"qa_output/secretKeys.jceks") if li_Success <> 1 then Write-Debug loo_Jceks.LastErrorText destroy loo_Jceks destroy loo_Prng return end if // We can also emit as a JWK Set.. loo_SbJson = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbJson.ConnectToNewObject("Chilkat.StringBuilder") li_Success = loo_Jceks.ToJwkSet("secret",loo_SbJson) if li_Success <> 1 then Write-Debug loo_Jceks.LastErrorText destroy loo_Jceks destroy loo_Prng destroy loo_SbJson return end if // Emit the JSON in pretty-printed (indented) form: loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.LoadSb(loo_SbJson) loo_Json.EmitCompact = 0 Write-Debug loo_Json.Emit() // Output is: // { // "keys": [ // { // "kty": "oct", // "alg": "AES", // "k": "vHekQQB0Gc1NvppapUTW2g", // "kid": "my aes key" // }, // { // "kty": "oct", // "alg": "BLOWFISH", // "k": "qHsdXaJsXicVCZbK8l8hJQpYOa0GkiO9gsRK9WLtht8", // "kid": "my blowfish key" // }, // { // "kty": "oct", // "alg": "HMAC_SHA256", // "k": "VGhpcyBpcyBteSBITUFDIGtleQ", // "kid": "my hmac key" // }, // { // "kty": "oct", // "alg": "CHACHA", // "k": "yNv832U43C9BcWvaQAH2_rG-GwfmpgT5JBRllWGQY1o", // "kid": "my chacha20 key" // } // ] // } // destroy loo_Jceks destroy loo_Prng destroy loo_SbJson destroy loo_Json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.