Sample Code for .Net Developers
This chapter lists the sample code and test files available to .Net developers.
It covers the following sections:
Sample Code and Tests for .Net API Developers
.Net API samples are installed when you perform installation using the InstallShield Wizard. To use .Net API samples, navigate to this directory:
<install directory>\
Tokenization\
samples --> API test files:
testTokenization
Program.cs
Test Code
All tests for the .Net API are combined into one file Program.cs. It contains the Main() function which calls the following tests listed below:
CT-V single-threaded sample test
This test example consists of 13 sequential operations. The following code begins the sample:
void TestST (String dataToEncrypt, String dbTable, String naeUser, String naePswd, String dbUser, String dbPswd);
(Here, dbTable
is a token vault name).
This test comprises the following sequential operations:
Insert a token.
String token = ts.insert(dataToEncrypt, dbTable, TokenService.LAST_FOUR_TOKEN, false);
Check if this value was tokenized or not.
String newToken = ts.getToken(dataToEncrypt, null, dbTable);
Verify that incorrect data were not tokenized.
newToken = ts.getToken(newData, null, dbTable);
Retrieve the plaintext value for this token by passing the token, and the token mask to get().
String value = ts.get(token, dbTable, 0);
Delete the token.
ts.deleteToken(token, dbTable);
Create your own token format.
int newFormat = ts.createNewFormat(3, 1, null, 1);
Insert a token using this new format.
token = ts.insert(dataToEncrypt, dbTable, newFormat, true);
Get tokens that were created on or before the specified date (defined by number of milliseconds since the beginning of epoch).
String[] dateTokens = ts.getTokensByDate(null, (long)msec, dbTable);
Delete the plaintext value.
ts.deleteValue(dataToEncrypt, dbTable);
Create test data tokens without storing them in Database (one-way masking).
String[] maskTokens = ts.mask(dateTokens, TokenService.SEQUENTIAL_TOKEN, "12345678998776111", false);
Insert multiple tokens.
tmResult = ts.insert(values, null, dbTable, TokenService.RANDOM_TOKEN, true, true);
Get multiple tokens.
tmResult = ts.get(tokens, null, dbTable, 0, true);
Test usage of SHA hash algorithms (calling insert/delete functions), regular expressions, splitters (slicers) and splicers (calling createNewFormat/insert functions).
shaRegexSplicerTests(ts, dbTable);
Stress Test for Insert Batch Operations
TestBatchInsert (dbTable, naeUser, naePswd, dbUser, dbPswd);
Stress Test for Delete Batch Operations
TestBatchDelete (dbTable, naeUser, naePswd, dbUser, dbPswd);
Unicode Test: tokenize various Unicode strings, detokenize them back, compare with original ones
void TestUniCode (String dbTable, String naeUser, String naePswd, String dbUser, String dbPswd);
Multithreaded Test
void TestMT (String[] dataToEncryptArr, String dbTable, String naeUser, String naePswd, String dbUser, String dbPswd);
The test inserts a token, gets a token, retrieves data associated with a token, then deletes a token. These operations are performed in different threads using one shared TokenService
object.
Advanced Multithreaded Test
TestAdvMT (dbTable, naeUser, naePswd, dbUser, dbPswd, numberOfThreads, steps, numberOfTokenSrvices, "RANDOM_TOKEN", "batch");
The test creates a new format, inserts a batch of tokens, gets a batch of tokens, retrieves a batch of values associated with these tokens, gets a batch of tokens that were created on or before the specified date, then deletes a batch of tokens. These operations are performed in different threads using different shared TokenService
objects.
Sample Code and Tests for .Net Web Service Developers
.Net Web service samples are installed when you perform installation using the InstallShield Wizard. To use .Net Web service samples, navigate to these directories:
<install directory>\
Tokenization\
samples\
testTokenWebService\ ProgramWS.cs
TestUnicodeWS.cs
Test Code
All tests for Web Services are combined into two files: ProgramWS.cs
and TestUnicodeWS.cs
.
ProgramWS.cs
contains the Main() function which calls the following tests:
Main Web Services test
RunTestWS (naeUser, naePswd, dbUser, dbPswd, dbTable);
This test consists of the following sequential operations:
insert token;
get a value for this token;
insert batch of tokens with custom data;
get batch of values for these tokens;
delete a value;
create a new format for certain token's length;
insert a token with custom data;
insert batch of tokens with custom data using dates;
get batch of values for these tokens;
insert a token using special characters;
get a value for this token;
mask operation;
get tokens by date with custom data;
insert batch operation, where one value will fail to tokenize, but the entire batch won't fail;
get batch operation, where one invalid element in the String array won't cause the entire operation to fail;
stress test for insert/delete batch operations;
Unicode Web Services Test
This tokenizes various Unicode strings, detokenizes them back, and compares results with original values.
TestUnicodeWS.RunTestUnicodeWS(naeUser, naePswd, dbUser, dbPswd, dbTable);