Search code examples
xquerymarklogic

In XQuery, how do you obfuscate a text string and maintain its character length on output?


I need to obfuscate the text content of an element. Let’s say, for example, a plan ID. The plan ID may appear several times in one document or across different documents. I need the obfuscated plan ID to be unique and consistent (always map 12345 to abc72) and limited to only 5 characters. I would prefer not to have a separate document that exists that would be used as the mapping file or contain keys.

A simple hash function would not work because of the character length limitation. Any other ideas? I’d like to stick with doing this in pure XQuery.


Solution

  • You could use fn:translate (similar to unix tr command) to reliably convert one character to another. This is similar to good old rot13, but more flexible and powerful.

    You could also build on this, by using a different fixed translation for each position in your text strings, as well.