org.bouncycastle.util.encoders.EncoderException Java Examples
The following examples show how to use
org.bouncycastle.util.encoders.EncoderException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AESSensitivePropertyProvider.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Returns the encrypted cipher text. * * @param unprotectedValue the sensitive value * @return the value to persist in the {@code nifi.properties} file * @throws SensitivePropertyProtectionException if there is an exception encrypting the value */ @Override public String protect(String unprotectedValue) throws SensitivePropertyProtectionException { if (unprotectedValue == null || unprotectedValue.trim().length() == 0) { throw new IllegalArgumentException("Cannot encrypt an empty value"); } // Generate IV byte[] iv = generateIV(); if (iv.length < IV_LENGTH) { throw new IllegalArgumentException("The IV (" + iv.length + " bytes) must be at least " + IV_LENGTH + " bytes"); } try { // Initialize cipher for encryption cipher.init(Cipher.ENCRYPT_MODE, this.key, new IvParameterSpec(iv)); byte[] plainBytes = unprotectedValue.getBytes(StandardCharsets.UTF_8); byte[] cipherBytes = cipher.doFinal(plainBytes); logger.info(getName() + " encrypted a sensitive value successfully"); return base64Encode(iv) + DELIMITER + base64Encode(cipherBytes); // return Base64.toBase64String(iv) + DELIMITER + Base64.toBase64String(cipherBytes); } catch (BadPaddingException | IllegalBlockSizeException | EncoderException | InvalidAlgorithmParameterException | InvalidKeyException e) { final String msg = "Error encrypting a protected value"; logger.error(msg, e); throw new SensitivePropertyProtectionException(msg, e); } }
Example #2
Source File: AESSensitivePropertyProvider.java From nifi-registry with Apache License 2.0 | 5 votes |
/** * Returns the encrypted cipher text. * * @param unprotectedValue the sensitive value * @return the value to persist in the {@code nifi.properties} file * @throws SensitivePropertyProtectionException if there is an exception encrypting the value */ @Override public String protect(String unprotectedValue) throws SensitivePropertyProtectionException { if (unprotectedValue == null || unprotectedValue.trim().length() == 0) { throw new IllegalArgumentException("Cannot encrypt an empty value"); } // Generate IV byte[] iv = generateIV(); if (iv.length < IV_LENGTH) { throw new IllegalArgumentException("The IV (" + iv.length + " bytes) must be at least " + IV_LENGTH + " bytes"); } try { // Initialize cipher for encryption cipher.init(Cipher.ENCRYPT_MODE, this.key, new IvParameterSpec(iv)); byte[] plainBytes = unprotectedValue.getBytes(StandardCharsets.UTF_8); byte[] cipherBytes = cipher.doFinal(plainBytes); logger.info(getName() + " encrypted a sensitive value successfully"); return base64Encode(iv) + DELIMITER + base64Encode(cipherBytes); // return Base64.toBase64String(iv) + DELIMITER + Base64.toBase64String(cipherBytes); } catch (BadPaddingException | IllegalBlockSizeException | EncoderException | InvalidAlgorithmParameterException | InvalidKeyException e) { final String msg = "Error encrypting a protected value"; logger.error(msg, e); throw new SensitivePropertyProtectionException(msg, e); } }
Example #3
Source File: AESSensitivePropertyProvider.java From nifi with Apache License 2.0 | 5 votes |
/** * Returns the encrypted cipher text. * * @param unprotectedValue the sensitive value * @return the value to persist in the {@code nifi.properties} file * @throws SensitivePropertyProtectionException if there is an exception encrypting the value */ @Override public String protect(String unprotectedValue) throws SensitivePropertyProtectionException { if (unprotectedValue == null || unprotectedValue.trim().length() == 0) { throw new IllegalArgumentException("Cannot encrypt an empty value"); } // Generate IV byte[] iv = generateIV(); if (iv.length < IV_LENGTH) { throw new IllegalArgumentException("The IV (" + iv.length + " bytes) must be at least " + IV_LENGTH + " bytes"); } try { // Initialize cipher for encryption cipher.init(Cipher.ENCRYPT_MODE, this.key, new IvParameterSpec(iv)); byte[] plainBytes = unprotectedValue.getBytes(StandardCharsets.UTF_8); byte[] cipherBytes = cipher.doFinal(plainBytes); logger.debug(getName() + " encrypted a sensitive value successfully"); return base64Encode(iv) + DELIMITER + base64Encode(cipherBytes); // return Base64.toBase64String(iv) + DELIMITER + Base64.toBase64String(cipherBytes); } catch (BadPaddingException | IllegalBlockSizeException | EncoderException | InvalidAlgorithmParameterException | InvalidKeyException e) { final String msg = "Error encrypting a protected value"; logger.error(msg, e); throw new SensitivePropertyProtectionException(msg, e); } }