Token Generator Code Example - Token Generator Code Example - OnBase - Legacy Authentication Methods - OnBase/Legacy-Authentication-Methods/Foundation-23.1/Legacy-Authentication-Methods/Integration-for-Single-Sign-On/Enabling-OnBase-Entrust/Token-Generator-Code-Example - Foundation 23.1 - Foundation 23.1

Legacy Authentication Methods

Platform
OnBase
Product
Legacy Authentication Methods
Release
Foundation 23.1
License
Premier
Standard
Essential
ft:lastPublication
2025-10-15T22:11:06.181000
ft:locale
en-US

The following examples in C# try to generate a valid token. If successful, the token is displayed to the user. If the status is anything other than success, the status is displayed.

The following is a sample code to generate an asymmetric OnBase Entrust token:

TokenGenerator generator = new TokenGenerator();
TokenResult result = generator.GenerateToken("johnsmith");
if (result.Status == TokenGeneratorStatus.Success)
{
    MessageBox.Show("Generated token: " + result.Token);
}
else
{
    MessageBox.Show("Failed to create token: " + result.Status.ToString());
}

The following is a sample code to generate a symmetric OnBase Entrust token:

TokenGenerator generator = new TokenGenerator();
byte[] keyBytes = null; //Load the key from a secure location.
//This is a required operation on the key without this Entrust with Symmetric key will not work.
ProtectedMemory.Protect(keyBytes, MemoryProtectionScope.SameProcess);
TokenResult result = generator.GenerateTokenUsingSymmetricKey("johnsmith", keyBytes);
if (result.Status == TokenGeneratorStatus.Success)
{
    MessageBox.Show("Generated token: " + result.Token);
}
else
{
    MessageBox.Show("Failed to create token: " + result.Status.ToString());
}