Fetching Key Names
If the client application is connected to the server via a global session, only global keys can be fetched, whereas, if it is connected to the server via an authenticated session, you can fetch:
all global keys
all keys owned by the user
all keys available to groups, the user is associated with
Fetching all key names
To fetch list of key names that are accessible to the user.
Call the GetKeyNames
method from the NaeKeyManagement
class.
NaeKeyManagement nkm = new NaeKeyManagement(session);
string[] keyNames = nkm.GetKeyName();
Console.WriteLine("Keynames : ");
if (keyNames.Length != 0)
{
foreach (string keyName in keyNames)
{
Console.WriteLine(keyName);
}
}
Sample Output
Keynames :
test_user_1_key
test_getKeyNames_global_key
test_user_1_key3
test_user_1_key2
test_user_1_key1
The above code displays the list of all key names.
Fetching key names using multiple attributes
You can also filter out the result using custom attributes as search criteria. The NaeKeyNameAttr
class is used to set the search criteria.
The below table describes the list of input parameters that can be used as a search criteria.
Input Parameters | Default Value | Description |
---|---|---|
customAttributes | NA | Defines the list of custom attributes of the NaeCustomAttr class. These attributes are defined in the name-value pairs. If multiple custom attributes are defined, use the logical conjunctive operator in a search to help broaden or narrow its scope. The attrKey and attrValue are mandatory fields. |
ConjunctiveOperator | OR | Applies to the custom attributes provided. Valid values: • AND - returns keys that satisfy all specified conditions in the custom attributes. • OR - returns keys that satisfy any specified conditions in the custom attributes. |
keyOffset | 0 | Specifies the index of the key array. From this index onward, the key names will be received in the response. For example, if there are a total 10 keys and the keyOffset = 2 , then in response, keys will be listed starting from index 2 rather than 0. |
maxKeys | 10000 | Total keys received in response starting from the keyOffset defined. |
Fingerprint | NA | Searches keys based on the fingerprint defined. |
Output Parameters | Description |
---|---|
totalKeyCount | Displays total number of keys found on the CipherTrust Manager, matching the search criteria. |
keyCount | Displays number of keys returned after applying the keyOffset and maxKeys values. |
keyNames | Displays the list of key names in string[] type. |
To fetch key names using multiple attributes:
Create a list of custom attributes by creating multiple instances of the
NaeCustomAttr
class.NaeCustomAttr customAttribute1 = new NaeCustomAttr(); customAttribute1.attrKey = "x-CustomAttributeName"; customAttribute1.attrValue = "X-VAlue"; NaeCustomAttr customAttribute2 = new NaeCustomAttr(); customAttribute2.attrKey = "Y-CustomAttributeName"; customAttribute2.attrValue = "Y-Value"; List<NaeCustomAttr> lst = new List<NaeCustomAttr>(); lst.Add(customAttribute1); lst.Add(customAttribute2);
Create an instance of the
NaeKeyNameAttr
class and set the conjunctive operators, custom attributes, max keys, key offset, and finger print parameters.NaeKeyNameAttr attr = new NaeKeyNameAttr(); attr.ConjunctiveOpr = NaeKeyNameAttr.ConjunctiveOperator.OR; attr.CustomAttributes = lst; attr.maxKeys = 10; attr.keyOffset = 0; attr.fingerprint = "";
Call the
GetKeyNames
method from theNaeKeyManagement
class and pass the instance of theNaeKeyNameAttr
class as a parameter. The return type of theGetKeyNames
method is string[].nkm = new NaeKeyManagement(session); string[] keyNames = nkm.GetKeyNames(attr); Console.WriteLine("Keynames : "); if (keyNames.Length != 0) { foreach (string keyName in keyNames) { Console.WriteLine(keyName); } }
Sample Output
Keynames : test_user_1_key test_getKeyNames_global_key test_user_1_key3 test_user_1_key2 test_user_1_key1
Get the Total Key Count and Key Count using the
NaeKeyNameAttr
instance.Console.WriteLine("TotalKeyCount = " + attr.totalKeyCount); Console.WriteLine("KeyCount = " + attr.keyCount);
Sample Output
TotalKeyCount = 9 KeyCount = 3