Encryptic
Earlier
we considered using straight Base-64 for hiding sensitive data from prying eyes.
Let's take it a step further and actually encrypt the data using a known password.
href="https://aptframework.dev.java.net/jelly/pbe.html">
border="0" width="32" height="32" align="left" hspace="8"/>Click here to read "Encryptic, a cover story"
Part of the "Jelly Beans" part of a trilogy in 42 parts
Code Snippet
We implement the following class to support password-based encryption
using the DES algorithm.
public class PBECipher {
private static final String pbeAlgorithm = "PBEWithMD5AndDES";
private static final String defaultPassword = "ssh ssh!";
...
public PBECipher() {
this(defaultPassword);
}
public PBECipher(String password) {
try {
parameterSpec = new PBEParameterSpec(salt, iterationCount);
secretKey = createSecretKey(password);
encryptCipher = createEncryptCipher();
decryptCipher = createDecryptCipher();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
...
public String decrypt(String string) {
try {
return new String(decryptCipher.doFinal(Base64.decode(string)));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
where we instantiate a PBEParameterSpec with an arbitrary 8-byte salt and iterationCount.
- Login or register to post comments
- Printer-friendly version
- evanx's blog
- 815 reads





