
Untitled
By: a guest on
Sep 13th, 2012 | syntax:
None | size: 1.05 KB | hits: 12 | expires: Never
protected void decryptProps(final Properties props) {
final String keystore = props.getProperty("keystore.filename");
final FileInputStream fs = new FileInputStream(keystore);
final KeyStore jks = KeyStore.getInstance("JCEKS");
jks.load(fs, storepass.toCharArray());
fs.close();
final String storepass = props.getProperty("keystore.password");
final Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, (PrivateKey) jks.getKey("rice-rsa-key", storepass.toCharArray()));
for (final String key : props.stringPropertyNames()) {
if (key.endsWith(".encrypted")) {
final String prefix = key.substring(0, key.indexOf(".encrypted"));
final String encrypted_str = props.getProperty(key);
props.setProperty(prefix + ".password",
new String(cipher.doFinal(new BASE64Decoder().decodeBuffer(encrypted_str))));
}
}
}