-
-
Notifications
You must be signed in to change notification settings - Fork 6
Encrypt and decrypt with obfuscation
Asterios Raptis edited this page Sep 4, 2017
·
1 revision
In this section we describe how to encrypt a message with the classes and interfaces that mystic-crypt library provides.
There are many forms of encrypting a message, one of them is to obfuscate it.
Here's an example: 917632854
To do that we need a custom map that defines our mapping. ´
final Map<String, String> charmap = new HashMap<>();
charmap.put("1", "I");
charmap.put("2", "Z");
charmap.put("3", "Eh");
charmap.put("4", "Ao");
charmap.put("5", "Wi");
charmap.put("6", "Fi");
charmap.put("7", "Ue");
charmap.put("8", "H");
charmap.put("9", "K");
We now give this custom map to a KeyRule object that we use in a Obfuscator. ´
final SimpleKeyRule charreplaceRule = new SimpleKeyRule(charmap);
String toObfuscatedString = "917632854";
Obfuscatable obfuscator = new Obfuscator(charreplaceRule, toObfuscatedString);
Now we can obfuscate the given string '917632854' and the given custom map with calling the obfuscate() method: ´
String actual = obfuscator.obfuscate();
String expected = "KIUeFiEhZHWiAo";
AssertJUnit.assertEquals(expected, actual);
All character you will not define in this custom map will stay the same so if you give the obfuscator an empty map the given text will stay the same as before.
This is a pretty decent encryption scheme.