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()); }