Skip to content

Instantly share code, notes, and snippets.

@konsolas
Last active October 2, 2015 16:39
Show Gist options
  • Save konsolas/35b6c609399544d4ede0 to your computer and use it in GitHub Desktop.
Save konsolas/35b6c609399544d4ede0 to your computer and use it in GitHub Desktop.
import me.konsolas.stuff.idk.HashMaker;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Map;
import java.util.TreeMap;
public class HardToDebugHashMap {
private Map<String, Object> resultsMap = new TreeMap<>();
public Object add(String key, Object value) {
String encKey;
try {
SecretKey secKey = new SecretKeySpec(HashMaker.makeHashRaw("MD5", key), "AES");
Cipher aesCipher = Cipher.getInstance("AES");
byte[] byteText = key.getBytes();
aesCipher.init(Cipher.ENCRYPT_MODE, secKey);
byte[] byteCipherText = aesCipher.doFinal(byteText);
encKey = new String(byteCipherText);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
resultsMap.put(encKey, value);
return this;
}
public Object get(String key) {
String encKey;
try {
SecretKey secKey = new SecretKeySpec(HashMaker.makeHashRaw("MD5", key), "AES");
Cipher aesCipher = Cipher.getInstance("AES");
byte[] byteText = key.getBytes();
aesCipher.init(Cipher.ENCRYPT_MODE, secKey);
byte[] byteCipherText = aesCipher.doFinal(byteText);
encKey = new String(byteCipherText);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return resultsMap.get(encKey);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment