public final void setPoolSize(final int poolSize) { this.encryptor.setPoolSize(poolSize) ; }//EOM
@VisibleForTesting void createEncryptors(String password) { if (password == null) { throw new ValidationException( "may not be null - " + this.getClass().getName() + ".password = null" ); } final PooledPBEByteEncryptor pooledPBEByteEncryptor = new PooledPBEByteEncryptor(); pooledPBEByteEncryptor.setPasswordCharArray(password.toCharArray()); pooledPBEByteEncryptor.setPoolSize(Runtime.getRuntime().availableProcessors()); this.byteEncryptor = pooledPBEByteEncryptor; final PooledPBEStringEncryptor pooledStringEncryptor = new PooledPBEStringEncryptor(); pooledStringEncryptor.setPasswordCharArray(password.toCharArray()); pooledStringEncryptor.setPoolSize(Runtime.getRuntime().availableProcessors()); this.stringEncryptor = pooledStringEncryptor; // Dereference the password so it will get garbage collected and moved // out of memory as an immutable String. this.password = null; }
/** * Configure method for Token generation configurations and ENCRYPTOR configure * * @param configuration confiuration for auth bundle */ public static void configure(TokenBasedAuthConfiguration configuration) { ENCRYPTOR.setPoolSize(configuration.getPoolSize()); // This would be a good value for a 4-core system if (configuration.getServerPassword().equals("auto")) { ENCRYPTOR.setPassword(UUID.randomUUID().toString()); } else { ENCRYPTOR.setPassword(configuration.getServerPassword()); } ENCRYPTOR.setAlgorithm(configuration.getAlgorithm()); ENCRYPTOR.initialize(); BasicToken.defaultMaxAge = configuration.getMaxage(); //Create cache for permissions. cache = CacheBuilder.newBuilder() .expireAfterAccess(defaultMaxAge, TimeUnit.SECONDS) .expireAfterWrite(defaultMaxAge, TimeUnit.SECONDS) .build(); }
/** * Configure method for Token generation configurations and encryptor configure * * @param configuration confiuration for auth bundle */ public static void configure(TokenBasedAuthConfiguration configuration) { encryptor.setPoolSize(configuration.getPoolSize()); // This would be a good value for a 4-core system if (configuration.getServerPassword().equals("auto")) { encryptor.setPassword(UUID.randomUUID().toString()); } else { encryptor.setPassword(configuration.getServerPassword()); } encryptor.setAlgorithm(configuration.getAlgorithm()); encryptor.initialize(); BasicToken.defaultMaxAge = configuration.getMaxage(); //Create cache for permissions. cache = CacheBuilder.newBuilder() .expireAfterAccess(defaultMaxAge, TimeUnit.SECONDS) .expireAfterWrite(defaultMaxAge, TimeUnit.SECONDS) .build(); }
public class EncryptionUtil { static PooledPBEStringEncryptor encryptor = null; static { encryptor = new PooledPBEStringEncryptor(); encryptor.setPoolSize(4); // There are various approaches to pull this configuration via system level properties. encryptor.setPassword("parashar"); encryptor.setAlgorithm("PBEWITHMD5ANDDES"); } public static String encrypt(String input) { return encryptor.encrypt(input); } public static String decrypt(String encryptedMessage) { return encryptor.decrypt(encryptedMessage); } }