Tokenize/Detokenize Date
Tokenize Date
Create
Date2ParameterSpec. PassdateFormatScheme,preserve,startYear,endYear, andtweakDataas arguments.Create an
NAESessionobject. Pass Key Manager username and password as arguments.Obtain an instance of the key you want to use for the tokenization operation.
Get
TokenizationServicefrom theTokenizationFactory. Passalgorithm,key, andDate2ParameterSpecas arguments.Invoke the
tokenizemethod of theTokenizationService. Pass the data in byte array (date to be tokenized) anddateFormatas arguments.
Code sample
This sample shows how to tokenize date using Date2 algorithm.
Date2ParameterSpec date2ParameterSpec = new Date2ParameterSpec.Date2ParameterBuilder(dateFormatScheme).setPreserve(preserve).setStartYear(startYear).setEndYear(endYear).setTweakData(tweakData).build();
NAESession session = NAESession.getSession(username, password.toCharArray());
NAEKey key = NAEKey.getSecretKey(keyName, session);
TokenizationService tokenizationService = TokenizationFactory.getTokenizationService("DATE2", key, date2ParameterSpec);
byte[] tokenizedOutput = tokenizationService.tokenize(dateToTokenize.getBytes(), dateFormat);
Detokenize Date
Create
Date2ParameterSpec. PassdateFormatScheme,preserve,startYear,endYear, andtweakDataas arguments.Create an
NAESessionobject. Pass Key Manager username and password as arguments.Obtain an instance of the key you want to use for the detokenization operation.
Get
TokenizationServicefrom theTokenizationFactory. Passalgorithm,key, andDate2ParameterSpecas arguments.Invoke the
detokenizemethod of theTokenizationService. Pass the data in byte array (date to be detokenized) anddateFormatas arguments.
Code sample
This sample shows how to detokenize date using Date2 algorithm.
Date2ParameterSpec date2ParameterSpec = new Date2ParameterSpec.Date2ParameterBuilder(dateFormatScheme).setPreserve(preserve).setStartYear(startYear).setEndYear(endYear).setTweakData(tweakData).build();
NAESession session = NAESession.getSession(username, password.toCharArray());
NAEKey key = NAEKey.getSecretKey(keyName, session);
TokenizationService tokenizationService = TokenizationFactory.getTokenizationService("DATE2", key, date2ParameterSpec);
byte[] detokenizedOutput = tokenizationService.detokenize(tokenizedOutput, dateFormat);
Note
During detokenization, you must pass the same arguments to Date2ParameterSpec that you used during the tokenization operation.
Cleanup
After performing tokenization/detokenization, this API is used to cleanup the resources allocated to the memory.
tokenizationService.cleanup();