Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 13th, 2012  |  syntax: None  |  size: 1.05 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     protected void decryptProps(final Properties props) {
  2.         final String keystore = props.getProperty("keystore.filename");
  3.         final FileInputStream fs = new FileInputStream(keystore);
  4.         final KeyStore jks = KeyStore.getInstance("JCEKS");
  5.         jks.load(fs, storepass.toCharArray());                
  6.         fs.close();
  7.  
  8.         final String storepass = props.getProperty("keystore.password");
  9.        
  10.         final Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
  11.         cipher.init(Cipher.DECRYPT_MODE, (PrivateKey) jks.getKey("rice-rsa-key", storepass.toCharArray()));
  12.  
  13.         for (final String key : props.stringPropertyNames()) {
  14.             if (key.endsWith(".encrypted")) {
  15.                 final String prefix = key.substring(0, key.indexOf(".encrypted"));
  16.                 final String encrypted_str = props.getProperty(key);
  17.                 props.setProperty(prefix + ".password",
  18.                                   new String(cipher.doFinal(new BASE64Decoder().decodeBuffer(encrypted_str))));
  19.             }
  20.         }
  21.        
  22.     }