Java Code Examples for javax.crypto.BadPaddingException#getMessage()
The following examples show how to use
javax.crypto.BadPaddingException#getMessage() .
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: Key.java From fernet-java8 with Apache License 2.0 | 6 votes |
/** * <p>Decrypt the payload of a Fernet token.</p> * * <p>Warning: Do not call this unless the cipher text has first been verified. Attempting to decrypt a cipher text * that has been tampered with will leak whether or not the padding is correct and this can be used to decrypt * stolen cipher text.</p> * * @param cipherText * the verified padded encrypted payload of a token. The length <em>must</em> be a multiple of 16 (128 * bits). * @param initializationVector * the random bytes used in the AES encryption of the token * @return the decrypted payload * @see Key#encrypt(byte[], IvParameterSpec) */ @SuppressWarnings("PMD.LawOfDemeter") protected byte[] decrypt(final byte[] cipherText, final IvParameterSpec initializationVector) { try { final Cipher cipher = Cipher.getInstance(getCipherTransformation()); cipher.init(DECRYPT_MODE, getEncryptionKeySpec(), initializationVector); return cipher.doFinal(cipherText); } catch (final NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException e) { // this should not happen as we use an algorithm (AES) and padding // (PKCS5) that are guaranteed to exist. // in addition, we validate the encryption key and initialization vector up front throw new IllegalStateException(e.getMessage(), e); } catch (final BadPaddingException bpe) { throw new TokenValidationException("Invalid padding in token: " + bpe.getMessage(), bpe); } }
Example 2
Source File: BrokenJCEBlockCipher.java From RipplePower with Apache License 2.0 | 6 votes |
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, java.security.InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
Example 3
Source File: BaseWrapCipher.java From RipplePower with Apache License 2.0 | 6 votes |
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { if (wrapEngine == null) { return engineDoFinal(encoded, 0, encoded.length); } else { return wrapEngine.wrap(encoded, 0, encoded.length); } } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
Example 4
Source File: BaseCipherSpi.java From RipplePower with Apache License 2.0 | 6 votes |
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { if (wrapEngine == null) { return engineDoFinal(encoded, 0, encoded.length); } else { return wrapEngine.wrap(encoded, 0, encoded.length); } } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
Example 5
Source File: BrokenJCEBlockCipher.java From ripple-lib-java with ISC License | 6 votes |
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, java.security.InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
Example 6
Source File: BaseWrapCipher.java From ripple-lib-java with ISC License | 6 votes |
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { if (wrapEngine == null) { return engineDoFinal(encoded, 0, encoded.length); } else { return wrapEngine.wrap(encoded, 0, encoded.length); } } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
Example 7
Source File: BaseCipherSpi.java From ripple-lib-java with ISC License | 6 votes |
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { if (wrapEngine == null) { return engineDoFinal(encoded, 0, encoded.length); } else { return wrapEngine.wrap(encoded, 0, encoded.length); } } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }