Generate Secrets
This generator can be used to create randomly generated secret.
Method: generateSecret(length: Int)
Info
If you want to generate a secret that can be used as a shared secret between the client and the server, there is the generateSecret function. The default behavior of the function is to generate a 10 character long secret and convert it to a Base32Secret instance. Optionally you can specify the length of the plain input to the base32 encoding secret.
Usage
secretGenerator.generateSecret(length = 3)
The generated secret will be returned as a Base32Secret object, similar to this one:
Base32Secret(
secretAsString = "IJAUCQSBIJAUEQKBIJBECQKCIJAUCQSCIJAUCQKCIFAUCQKC",
secretAsByteArray = [B@372f7a8d
)
Arguments
Argument | Type | Default | Constraint |
---|---|---|---|
length | Int | 10 | >= 0 |
Method: generateSecret(algorithm: HashAlgorithm)
Info
If you want to generate a secret that can be used as a shared secret between client and server, there is the function generateSecret. You can pass a supported HMAC algorithm as input to the function to generate a secret with the recommended length of the algorithm.
Key | Length |
---|---|
SHA1 | 20 |
SHA256 | 32 |
SHA512 | 64 |
Usage
secretGenerator.generateSecret(HashAlgorithm.SHA1)
The generated secret will be returned as a Base32Secret object, similar to this one:
Base32Secret(
secretAsString = "IJAUCQSBIJAUEQKBIJBECQKCIJAUCQSCIJAUCQKCIFAUCQKC",
secretAsByteArray = [B@372f7a8d
)
Arguments
Argument | Type | Default | Constraint |
---|---|---|---|
algorithm | HashAlgorithm | - | - |