Class SecureKey() Professional

Class function of the SecureKey() class

Description

The class SecureKey acts as a key generator and a key provider.

Key generation is a very important aspect in secure environments. The key is generated by a random generator and hashed by a secure hashing algorithm.

Class methods
:new()
Creates an instance of the SecureKey class.
:generate()
Creates an instance of the SecureKey class holding a generated key.
:sha256()
Hash data with the SHA-256 algorithm.
Methods
:destroy()
Destroys the internal buffers holding the key.
:setStrKey()
Assign a key in hexadecimal notation to the object executing the method.
:toBin()
Converts the hexadecimal form of the key into a binary representation.
:toString()
Converts the binary key to a hexadecimal notation.
Examples
Generating a new key
// In this example, SecureKey() is used 
// to generate a new key 

#include "crypt.ch" 

PROCEDURE MAIN 
   LOCAL oKey 
    
   // generate a key with 128 bit length 
   oKey := SecureKey():generate(128) 

   // print key in hexadecimal notation, using 
   // a colon to separate groups of 2 characters 
   // for better readability 

   ? oKey:toString(,":") 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.