Package org.jasypt.exceptions

Examples of org.jasypt.exceptions.EncryptionOperationNotPossibleException


        } catch (EncryptionOperationNotPossibleException e) {
            throw e;
        } catch (Exception e) {
            // If digest fails, it is more secure not to return any information
            // about the cause in nested exceptions. Simply fail.
            throw new EncryptionOperationNotPossibleException();
        }
       
    }
View Full Code Here


        String processedDigest = digest;
       
        if (processedDigest != null) {
            if (this.prefix != null) {
                if (!processedDigest.startsWith(this.prefix)) {
                    throw new EncryptionOperationNotPossibleException(
                            "Digest does not start with required prefix \"" + this.prefix + "\"");
                }
                processedDigest = processedDigest.substring(this.prefix.length());
            }
            if (this.suffix != null) {
                if (!processedDigest.endsWith(this.suffix)) {
                    throw new EncryptionOperationNotPossibleException(
                            "Digest does not end with required suffix \"" + this.suffix + "\"");
                }
                processedDigest = processedDigest.substring(0, processedDigest.length() - this.suffix.length());
            }
        }
       

        if (message == null) {
            return (processedDigest == null);
        } else if (processedDigest == null) {
            return false;
        }

       
        // Check initialization
        if (!isInitialized()) {
            initialize();
        }
       
        try {

            // Normalize Unicode message to NFC form
            String normalizedMessage = null;
            if (! this.unicodeNormalizationIgnored) {
                normalizedMessage = Normalizer.normalizeToNfc(message);
            } else {
                normalizedMessage = message;
            }
           
            // We get a valid byte array from the message, in the
            // fixed MESSAGE_CHARSET that the digest operations use.
            final byte[] messageBytes = normalizedMessage.getBytes(MESSAGE_CHARSET);
           

            // The BASE64 or HEXADECIMAL encoding is reversed and the digest
            // is converted into a byte array.
            byte[] digestBytes = null;
            if (this.stringOutputTypeBase64) {
                // The digest must be a US-ASCII String BASE64-encoded
                digestBytes = processedDigest.getBytes(DIGEST_CHARSET);
                digestBytes = this.base64.decode(digestBytes);
            } else {
                digestBytes = CommonUtils.fromHexadecimal(processedDigest);
            }
           
            // The StandardByteDigester is asked to match message to digest.
            return this.byteDigester.matches(messageBytes, digestBytes);
       
        } catch (EncryptionInitializationException e) {
            throw e;
        } catch (EncryptionOperationNotPossibleException e) {
            throw e;
        } catch (Exception e) {
            // If digest fails, it is more secure not to return any information
            // about the cause in nested exceptions. Simply fail.
            throw new EncryptionOperationNotPossibleException();
        }

    }
View Full Code Here

            return digest;
           
        } catch (Exception e) {
            // If digest fails, it is more secure not to return any information
            // about the cause in nested exceptions. Simply fail.
            throw new EncryptionOperationNotPossibleException();
        }
       
    }
View Full Code Here

                    // Compute size figures and perform length checks
                    int digestSaltSize = this.saltSizeBytes;
                    if (this.digestLengthBytes > 0) {
                        if (this.useLenientSaltSizeCheck) {
                            if (digest.length < this.digestLengthBytes) {
                                throw new EncryptionOperationNotPossibleException();
                            }
                            digestSaltSize = digest.length - this.digestLengthBytes;
                        } else {
                            if (digest.length != (this.digestLengthBytes + this.saltSizeBytes)) {
                                throw new EncryptionOperationNotPossibleException();
                            }
                        }
                    } else {
                        // Salt size check behaviour cannot be set to lenient
                        if (digest.length < this.saltSizeBytes) {
                            throw new EncryptionOperationNotPossibleException();
                        }
                    }
                   
                    if (!this.invertPositionOfPlainSaltInEncryptionResults) {
                        salt = new byte[digestSaltSize];
                        System.arraycopy(digest, 0, salt, 0, digestSaltSize);
                    } else {
                        salt = new byte[digestSaltSize];
                        System.arraycopy(digest, digest.length - digestSaltSize, salt, 0, digestSaltSize);
                    }
                   
                } else {
                    salt = this.saltGenerator.generateSalt(this.saltSizeBytes);
                }
            }
           
            // Digest the message with the extracted digest.
            final byte[] encryptedMessage = digest(message, salt);
           
            // If, using the same salt, digests match, then messages too.
            return (Arrays.equals(encryptedMessage, digest));
       
        } catch (Exception e) {
            // If digest fails, it is more secure not to return any information
            // about the cause in nested exceptions. Simply fail.
            throw new EncryptionOperationNotPossibleException();
        }
       
    }
View Full Code Here

            System.arraycopy(byteArray, 0, processedByteArray, 0, (initialSize - 4));
           
            final int expectedSize =
                NumberUtils.intFromByteArray(encryptedMessageExpectedSizeBytes);
            if (expectedSize < 0 || expectedSize > maxSafeSizeInBytes()) {
                throw new EncryptionOperationNotPossibleException();
            }

            // If expected and real sizes do not match, we will need to pad
            // (this happens because BigInteger removes 0x0's and -0x1's in
            // the leftmost side).
View Full Code Here

           
        } catch (InvalidKeyException e) {
            // The problem could be not having the unlimited strength policies
            // installed, so better give a usefull error message.
            handleInvalidKeyException(e);
            throw new EncryptionOperationNotPossibleException();
        } catch (Exception e) {
            // If encryption fails, it is more secure not to return any
            // information about the cause in nested exceptions. Simply fail.
            throw new EncryptionOperationNotPossibleException();
        }
       
    }
View Full Code Here

        }
       
        if (this.saltGenerator.includePlainSaltInEncryptionResults()) {
            // Check that the received message is bigger than the salt
            if (encryptedMessage.length <= this.saltSizeBytes) {
                throw new EncryptionOperationNotPossibleException();
            }
        }
   
        try {

            // If we are using a salt generator which specifies the salt
            // to be included into the encrypted message itself, get it from
            // there. If not, the salt is supposed to be fixed and thus the
            // salt generator can be safely asked for it again.
            byte[] salt = null;
            byte[] encryptedMessageKernel = null;
            if (this.saltGenerator.includePlainSaltInEncryptionResults()) {
               
                final int saltStart = 0;
                final int saltSize =
                    (this.saltSizeBytes < encryptedMessage.length? this.saltSizeBytes : encryptedMessage.length);
                final int encMesKernelStart =
                    (this.saltSizeBytes < encryptedMessage.length? this.saltSizeBytes : encryptedMessage.length);
                final int encMesKernelSize =
                    (this.saltSizeBytes < encryptedMessage.length? (encryptedMessage.length - this.saltSizeBytes) : 0);
               
                salt = new byte[saltSize];
                encryptedMessageKernel = new byte[encMesKernelSize];
               
                System.arraycopy(encryptedMessage, saltStart, salt, 0, saltSize);
                System.arraycopy(encryptedMessage, encMesKernelStart, encryptedMessageKernel, 0, encMesKernelSize);
               
            } else {
               
                salt = this.saltGenerator.generateSalt(this.saltSizeBytes);
                encryptedMessageKernel = encryptedMessage;
               
            }
           
           
            /*
             * Perform decryption using the Cipher
             */
            final PBEParameterSpec parameterSpec =
                new PBEParameterSpec(salt, this.keyObtentionIterations);

            byte[] decryptedMessage = null;
                
            synchronized (this.decryptCipher) {
                this.decryptCipher.init(
                        Cipher.DECRYPT_MODE, this.key, parameterSpec);
                decryptedMessage =
                    this.decryptCipher.doFinal(encryptedMessageKernel);
            }

            // Return the results
            return decryptedMessage;
           
           
        } catch (InvalidKeyException e) {
            // The problem could be not having the unlimited strength policies
            // installed, so better give a usefull error message.
            handleInvalidKeyException(e);
            throw new EncryptionOperationNotPossibleException();
        } catch (Exception e) {
            // If decryption fails, it is more secure not to return any
            // information about the cause in nested exceptions. Simply fail.
            throw new EncryptionOperationNotPossibleException();
        }
       
    }   
View Full Code Here

    private void handleInvalidKeyException(InvalidKeyException e) {

        if ((e.getMessage() != null) &&
                ((e.getMessage().toUpperCase().indexOf("KEY SIZE") != -1))) {
           
            throw new EncryptionOperationNotPossibleException(
                    "Encryption raised an exception. A possible cause is " +
                    "you are using strong encryption algorithms and " +
                    "you have not installed the Java Cryptography " +
                    "Extension (JCE) Unlimited Strength Jurisdiction " +
                    "Policy Files in this Java Virtual Machine");
View Full Code Here

        } catch (EncryptionOperationNotPossibleException e) {
            throw e;
        } catch (Exception e) {
            // If encryption fails, it is more secure not to return any
            // information about the cause in nested exceptions. Simply fail.
            throw new EncryptionOperationNotPossibleException();
        }
       
    }
View Full Code Here

        } catch (EncryptionOperationNotPossibleException e) {
            throw e;
        } catch (Exception e) {
            // If decryption fails, it is more secure not to return any
            // information about the cause in nested exceptions. Simply fail.
            throw new EncryptionOperationNotPossibleException();
        }

    }
View Full Code Here

TOP

Related Classes of org.jasypt.exceptions.EncryptionOperationNotPossibleException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.