/** * Main method of this class to be used as a command-line tool to get a crypted version of a resource password. * @param args the command-line arguments. * @throws Exception when an error occurs crypting the given resource password. */ public static void main(String[] args) throws Exception { System.out.println("Bitronix Transaction Manager " + Version.getVersion() + " password property crypter"); System.out.flush(); if (args.length < 1 || args.length > 2) { System.err.println("Usage: CryptoEngine <password> [cipher]"); System.err.println(" where:"); System.err.println(" <password> is mandatory and is the resource password to crypt"); System.err.println(" [cipher] is optional and is the cipher to be used to crypt the password"); System.exit(1); } String data = args[0]; String cipher = "DES"; if (args.length > 1) cipher = args[1]; String propertyValue = "{" + cipher + "}" + crypt(cipher, data); System.out.println("crypted password property value: " + propertyValue); }
private static String decrypt(String resourcePassword) throws Exception { int startIdx = resourcePassword.indexOf("{"); int endIdx = resourcePassword.indexOf("}"); if (startIdx != 0 || endIdx == -1) return resourcePassword; String cipher = resourcePassword.substring(1, endIdx); if (log.isDebugEnabled()) log.debug("resource password is encrypted, decrypting " + resourcePassword); return CryptoEngine.decrypt(cipher, resourcePassword.substring(endIdx + 1)); }
KeySpec keySpec = loadKeySpec(CRYPTO_PASSWORD.getBytes(), cipher); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(cipher); SecretKey secretKey = keyFactory.generateSecret(keySpec);
/** * Main method of this class to be used as a command-line tool to get a crypted version of a resource password. * @param args the command-line arguments. * @throws Exception when an error occurs crypting the given resource password. */ public static void main(String[] args) throws Exception { System.out.println("Bitronix Transaction Manager " + Version.getVersion() + " password property crypter"); System.out.flush(); if (args.length < 1 || args.length > 2) { System.err.println("Usage: CryptoEngine <password> [cipher]"); System.err.println(" where:"); System.err.println(" <password> is mandatory and is the resource password to crypt"); System.err.println(" [cipher] is optional and is the cipher to be used to crypt the password"); System.exit(1); } String data = args[0]; String cipher = "DES"; if (args.length > 1) cipher = args[1]; String propertyValue = "{" + cipher + "}" + crypt(cipher, data); System.out.println("crypted password property value: " + propertyValue); }
private static String decrypt(String resourcePassword) throws Exception { int startIdx = resourcePassword.indexOf("{"); int endIdx = resourcePassword.indexOf("}"); if (startIdx != 0 || endIdx == -1) return resourcePassword; String cipher = resourcePassword.substring(1, endIdx); if (log.isDebugEnabled()) { log.debug("resource password is encrypted, decrypting " + resourcePassword); } return CryptoEngine.decrypt(cipher, resourcePassword.substring(endIdx + 1)); } }
KeySpec keySpec = loadKeySpec(CRYPTO_PASSWORD.getBytes(), cipher); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(cipher); SecretKey secretKey = keyFactory.generateSecret(keySpec);
/** * Main method of this class to be used as a command-line tool to get a crypted version of a resource password. * @param args the command-line arguments. * @throws Exception when an error occurs crypting the given resource password. */ public static void main(String[] args) throws Exception { System.out.println("Bitronix Transaction Manager " + Version.getVersion() + " password property crypter"); System.out.flush(); if (args.length < 1 || args.length > 2) { System.err.println("Usage: CryptoEngine <password> [cipher]"); System.err.println(" where:"); System.err.println(" <password> is mandatory and is the resource password to crypt"); System.err.println(" [cipher] is optional and is the cipher to be used to crypt the password"); System.exit(1); } String data = args[0]; String cipher = "DES"; if (args.length > 1) cipher = args[1]; String propertyValue = "{" + cipher + "}" + crypt(cipher, data); System.out.println("crypted password property value: " + propertyValue); }
private static String decrypt(String resourcePassword) throws Exception { int startIdx = resourcePassword.indexOf("{"); int endIdx = resourcePassword.indexOf("}"); if (startIdx != 0 || endIdx == -1) return resourcePassword; String cipher = resourcePassword.substring(1, endIdx); if (log.isDebugEnabled()) log.debug("resource password is encrypted, decrypting " + resourcePassword); return CryptoEngine.decrypt(cipher, resourcePassword.substring(endIdx + 1)); }
KeySpec keySpec = loadKeySpec(CRYPTO_PASSWORD.getBytes(), cipher); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(cipher); SecretKey secretKey = keyFactory.generateSecret(keySpec);
/** * Main method of this class to be used as a command-line tool to get a crypted version of a resource password. * @param args the command-line arguments. * @throws Exception when an error occurs crypting the given resource password. */ public static void main(String[] args) throws Exception { System.out.println("Bitronix Transaction Manager " + Version.getVersion() + " password property crypter"); System.out.flush(); if (args.length < 1 || args.length > 2) { System.err.println("Usage: CryptoEngine <password> [cipher]"); System.err.println(" where:"); System.err.println(" <password> is mandatory and is the resource password to crypt"); System.err.println(" [cipher] is optional and is the cipher to be used to crypt the password"); System.exit(1); } String data = args[0]; String cipher = "DES"; if (args.length > 1) cipher = args[1]; String propertyValue = "{" + cipher + "}" + crypt(cipher, data); System.out.println("crypted password property value: " + propertyValue); }
private static String decrypt(String resourcePassword) throws Exception { int startIdx = resourcePassword.indexOf("{"); int endIdx = resourcePassword.indexOf("}"); if (startIdx != 0 || endIdx == -1) return resourcePassword; String cipher = resourcePassword.substring(1, endIdx); if (log.isDebugEnabled()) { log.debug("resource password is encrypted, decrypting " + resourcePassword); } return CryptoEngine.decrypt(cipher, resourcePassword.substring(endIdx + 1)); } }
KeySpec keySpec = loadKeySpec(CRYPTO_PASSWORD.getBytes(), cipher); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(cipher); SecretKey secretKey = keyFactory.generateSecret(keySpec);
public void testBuildXAFactory() throws Exception { ResourceBean rb = new ResourceBean() {}; rb.setMaxPoolSize(1); rb.setClassName(MockitoXADataSource.class.getName()); rb.getDriverProperties().setProperty("userName", "java"); rb.getDriverProperties().setProperty("password", "{DES}" + CryptoEngine.crypt("DES", "java")); XAPool<DummyResourceHolder, DummyStatefulHolder> xaPool = new XAPool<DummyResourceHolder, DummyStatefulHolder>(null, rb, null); assertEquals(0, xaPool.totalPoolSize()); assertEquals(0, xaPool.inPoolSize()); MockitoXADataSource xads = (MockitoXADataSource) xaPool.getXAFactory(); assertEquals("java", xads.getUserName()); assertEquals("java", xads.getPassword()); }
public void testBuildXAFactory() throws Exception { ResourceBean rb = new ResourceBean() {}; rb.setMaxPoolSize(1); rb.setClassName(MockitoXADataSource.class.getName()); rb.getDriverProperties().setProperty("userName", "java"); rb.getDriverProperties().setProperty("password", "{DES}" + CryptoEngine.crypt("DES", "java")); XAPool<DummyResourceHolder, DummyStatefulHolder> xaPool = new XAPool<DummyResourceHolder, DummyStatefulHolder>(null, rb, null); assertEquals(0, xaPool.totalPoolSize()); assertEquals(0, xaPool.inPoolSize()); MockitoXADataSource xads = (MockitoXADataSource) xaPool.getXAFactory(); assertEquals("java", xads.getUserName()); assertEquals("java", xads.getPassword()); }