GenerateSecretKey

Generates an encoded encryption key using the specified algorithm and key size

Method Signature

GenerateSecretKey(algorithm=[string], keySize=[numeric])

Arguments

Argument
Type
Required
Description
Default

algorithm

string

false

The algorithm to use for generating the key. The default is AES. Example values are: AES, DES, DESede, Blowfish, HmacSHA1, HmacSHA256, HmacSHA384, HmacSHA512

AES

keySize

numeric

false

The optional size of the key to generate. If not provided the default key size for the algorithm will be used

Examples

Generate an AES 128 bit Key

Generate an AES key and use it to encrypt and decrypt a secret.

Run Example

ex = {};
ex.KEY = generateSecretKey( "AES" );
ex.SECRET = "top secret";
ex.ENCRYPTED = encrypt( ex.SECRET, ex.KEY, "AES", "Base64" );
ex.DECRYPTED = decrypt( ex.ENCRYPTED, ex.KEY, "AES", "Base64" );
writeDump( ex );

Additional Examples

Run Example

ex = {};
ex.ALGO = "RC4";
ex.VALUE = "554122";
ex.KEY = GenerateSecretKey( ex.ALGO );
ex.ENC = Encrypt( ex.VALUE, ex.KEY, ex.ALGO );
ex.DEC = Decrypt( ex.ENC, ex.KEY, ex.ALGO );
dump( ex );

Last updated

Was this helpful?