Tokenize/Detokenize Date
Tokenize Date
Create
Date2ParameterSpec
. PassdateFormatScheme
,preserve
,startYear
,endYear
, andtweakData
as arguments.Create an
NAESession
object. Pass Key Manager username and password as arguments.Obtain an instance of the key you want to use for the tokenization operation.
Get
TokenizationService
from theTokenizationFactory
. Passalgorithm
,key
, andDate2ParameterSpec
as arguments.Invoke the
tokenize
method of theTokenizationService
. Pass the data in byte array (date to be tokenized) anddateFormat
as 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
, andtweakData
as arguments.Create an
NAESession
object. Pass Key Manager username and password as arguments.Obtain an instance of the key you want to use for the detokenization operation.
Get
TokenizationService
from theTokenizationFactory
. Passalgorithm
,key
, andDate2ParameterSpec
as arguments.Invoke the
detokenize
method of theTokenizationService
. Pass the data in byte array (date to be detokenized) anddateFormat
as 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();