/** * Decrypts the given string. * * @param string the string to decrypt * @return the decrypted string */ public String decrypt(String string) { return string != null ? encryption.decrypt(string) : null; }
/** * Encrypts the given string. * * @param string the string to encrypt * @return the encrypted string */ public String encrypt(String string) { return string != null ? encryption.encrypt(string) : null; }
@Test public void encryptDecryptAcrossDifferentEncryptionInstances() { char[] passphrase = "My very secret pass phrase".toCharArray(); String textToEncrypt = "Some text that needs to be encrypted."; Encryption encryption = Encryption.createEncryption(passphrase); String encrypted = encryption.encrypt(textToEncrypt); Encryption encryption2 = Encryption.createEncryption(passphrase); String decrypted = encryption2.decrypt(encrypted); assertEquals(textToEncrypt, decrypted); }
/** * Creates a new instance that will use the given passphrase for all encryption/decryption activities. * * @param passphrase the passphrase to encrypt/decrypt the credentials with * @return the new instance */ public static CredentialsEncryptor withPassphrase(char[] passphrase) { Encryption encryption = Encryption.createEncryption(passphrase); return new CredentialsEncryptor(encryption); }
/** * Creates a new Encryption instance that uses password-based encryption (PBE). The algorithm used to create the secret key is <i>PBEWithMD5AndDES</i>. * * @param passphrase the passphrase to apply when creating the secret key * @return the new Encryption instance * @throws RuntimeException with wrapped GeneralSecurityException in case of crypto-related exceptions */ public static Encryption createEncryption(char[] passphrase) { try { return createEncryptionThrowingException(passphrase); } catch (GeneralSecurityException e) { throw new RuntimeException("Cannot create Encryption instance: " + e.getMessage(), e); } }
pbeDcipher.init(Cipher.DECRYPT_MODE, pbeKey, ivSpec); return new Encryption(pbeEcipher, pbeDcipher);
/** * Creates a new instance that will use the given passphrase for all encryption/decryption activities. * * @param passphrase the passphrase to encrypt/decrypt the credentials with * @return the new instance */ public static CredentialsEncryptor withPassphrase(char[] passphrase) { Encryption encryption = Encryption.createEncryption(passphrase); return new CredentialsEncryptor(encryption); }
/** * Creates a new Encryption instance that uses password-based encryption (PBE). The algorithm used to create the secret key is <i>PBEWithMD5AndDES</i>. * * @param passphrase the passphrase to apply when creating the secret key * @return the new Encryption instance * @throws RuntimeException with wrapped GeneralSecurityException in case of crypto-related exceptions */ public static Encryption createEncryption(char[] passphrase) { try { return createEncryptionThrowingException(passphrase); } catch (GeneralSecurityException e) { throw new RuntimeException("Cannot create Encryption instance: " + e.getMessage(), e); } }
pbeDcipher.init(Cipher.DECRYPT_MODE, pbeKey, ivSpec); return new Encryption(pbeEcipher, pbeDcipher);
/** * Decrypts the given string. * * @param string the string to decrypt * @return the decrypted string */ public String decrypt(String string) { return string != null ? encryption.decrypt(string) : null; }
/** * Encrypts the given string. * * @param string the string to encrypt * @return the encrypted string */ public String encrypt(String string) { return string != null ? encryption.encrypt(string) : null; }