@ SuppressWarnings ( "PMD.LawOfDemeter" ) public 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 ) ; } }
Decrypt the payload of a Fernet token .