@Test public void testEncryptionUtils() throws EncryptionException { String clearText = RandomStringUtils.randomAlphanumeric(new Random().nextInt(10000) + 5) + UUID.randomUUID().toString(); String password = UUID.randomUUID().toString(); String encrypted = EncryptionUtils.encrypt(clearText, password); String decrypted = EncryptionUtils.decrypt(encrypted, password); Assert.assertEquals(decrypted, clearText); String salt = EncryptionUtils.getSalt(encrypted); String encryptedWithSalt = EncryptionUtils.encrypt(clearText, password, Base64Utils .decode(salt)); Assert.assertEquals(encrypted, encryptedWithSalt); String decryptedWithSalt = EncryptionUtils.decrypt(encryptedWithSalt, password); Assert.assertEquals(decrypted, decryptedWithSalt); String wrongPassword = UUID.randomUUID().toString(); String result = null; try { result = EncryptionUtils.decrypt(encryptedWithSalt, wrongPassword); } catch (EncryptionException e) { return; } if (result != null && result.equals(clearText)) { Assert.fail("Could decrypt a text (" + clearText + ") that was encrypted with password '" + password + "' with password '" + wrongPassword + "'"); } }
private EncryptionUtils() { }
EncryptionUtils { private EncryptionUtils() { } }
EncryptionUtils { private EncryptionUtils() { } private  EncryptionUtils(); }
EncryptionUtils { private EncryptionUtils() { } private  EncryptionUtils(); static String decrypt(String encryptedText, String password); static String encrypt(String clearText, String password); static String encrypt(String clearText, String password, byte[] salt); static byte[] generateSalt(); static byte[] generateSalt(int saltSize); static String getSalt(String encryptedText); }
EncryptionUtils { private EncryptionUtils() { } private  EncryptionUtils(); static String decrypt(String encryptedText, String password); static String encrypt(String clearText, String password); static String encrypt(String clearText, String password, byte[] salt); static byte[] generateSalt(); static byte[] generateSalt(int saltSize); static String getSalt(String encryptedText);  }