/** * Encrypts the provided string. * * @param input * String (UTF-8 encoded) to be encrypted * @return The encrypted version of the input string, or directly the input string if no * encryption key is configured or the string is already encrypted. */ public static String encrypt(String input) { if (encryptionService == null || input == null || input.length() == 0 || input.startsWith(ENCRYPTION_PREFIX)) { return input; } return ENCRYPTION_PREFIX + encryptionService.encrypt(input); }
/** * Encrypts the provided string. * * @param input * String (UTF-8 encoded) to be encrypted * @return The encrypted version of the input string, or directly the input string if no * encryption key is configured or the string is already encrypted. */ public static String encrypt(String input) { if (encryptionService == null || input == null || input.length() == 0 || input.startsWith(ENCRYPTION_PREFIX)) { return input; } return ENCRYPTION_PREFIX + encryptionService.encrypt(input); }
/** * Encrypts the provided string. * * @param input * String (UTF-8 encoded) to be encrypted * @return The encrypted version of the input string. */ public String encrypt(String input) { if (input == null || input.length() == 0) { return input; } byte[] inputBytes = input.getBytes(UTF_8); byte[] outputBytes = encrypt(inputBytes); return new String(outputBytes, UTF_8); }
/** * Encrypts the provided string. * @param input * String (UTF-8 encoded) to be encrypted * @return The encrypted version of the input string. */ public String encrypt(String input) { if (input == null || input.length() == 0) { return input; } byte[] inputBytes = input.getBytes(UTF_8); byte[] outputBytes = encrypt(inputBytes); return new String(outputBytes, UTF_8); }
/** * Initializes (or re-initializes) the {@link EncryptorService} by reading the configured * encryption key file. */ public static void initEncryptionService() { File encryptionKey = getEncryptionFile(); if (encryptionKey == null) { encryptionService = null; } else { encryptionService = new EncryptorService(encryptionKey); try { encryptionService.encrypt(ENCRYPTION_PREFIX); } catch (Exception e) { throw new LocalizableValidationException(e, "Error validating the encryption key!", "common.encryption.file.validation"); } } }
/** * Initializes (or re-initializes) the {@link EncryptorService} by reading the configured * encryption key file. */ public static void initEncryptionService() { File encryptionKey = getEncryptionFile(); if (encryptionKey == null) { encryptionService = null; } else { encryptionService = new EncryptorService(encryptionKey); try { encryptionService.encrypt(ENCRYPTION_PREFIX); } catch (Exception e) { throw new LocalizableValidationException(e, "Error validating the encryption key!", "common.encryption.file.validation"); } } }