Package org.jasypt.exceptions

Examples of org.jasypt.exceptions.EncryptionOperationNotPossibleException


           
        } 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;
            if (this.saltGenerator.includePlainSaltInEncryptionResults()) {
                salt = ArrayUtils.subarray(
                        encryptedMessage, 0, this.saltSizeBytes);
            } else {
                salt = this.saltGenerator.generateSalt(this.saltSizeBytes);
            }
           
           
            /*
             * Perform decryption using the Cipher
             */
            PBEParameterSpec parameterSpec =
                new PBEParameterSpec(salt, this.keyObtentionIterations);

            byte[] decryptedMessage = null;
           
            // If we are using a salt generator which specifies the salt
            // to be included into the encrypted message itself, we need to
            // extract the part of the encrypted message which really belongs
            // to the encryption result, and not the prepended salt.
            byte[] encryptedMessageKernel = null;
            if (this.saltGenerator.includePlainSaltInEncryptionResults()) {
                encryptedMessageKernel =
                    ArrayUtils.subarray(encryptedMessage, this.saltSizeBytes,
                            encryptedMessage.length);
            } else {
                encryptedMessageKernel = encryptedMessage;
            }
                
            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 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

        } 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 encryptedMessage;
       
        } 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 (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

    public static byte[] fromHexadecimal(String message) {
        if (message == null) {
            return null;
        }
        if ((message.length() % 2) != 0) {
            throw new EncryptionOperationNotPossibleException();
        }
        try {
            byte[] result = new byte[message.length() / 2];
            for (int i = 0; i < message.length(); i = i + 2) {
                int first = Integer.parseInt("" + message.charAt(i), 16);
                int second = Integer.parseInt("" + message.charAt(i + 1), 16);
                result[i/2] = (byte) (0x0 + ((first & 0xff) << 4) + (second & 0xff));
            }
            return result;
        } catch (Exception e) {
            throw new EncryptionOperationNotPossibleException();
        }
    }
View Full Code Here

    public static byte[] fromHexadecimal(final String message) {
        if (message == null) {
            return null;
        }
        if ((message.length() % 2) != 0) {
            throw new EncryptionOperationNotPossibleException();
        }
        try {
            final byte[] result = new byte[message.length() / 2];
            for (int i = 0; i < message.length(); i = i + 2) {
                final int first = Integer.parseInt("" + message.charAt(i), 16);
                final int second = Integer.parseInt("" + message.charAt(i + 1), 16);
                result[i/2] = (byte) (0x0 + ((first & 0xff) << 4) + (second & 0xff));
            }
            return result;
        } catch (Exception e) {
            throw new EncryptionOperationNotPossibleException();
        }
    }
View Full Code Here

         * If neither a StringEncryptor nor a TextEncryptor can be retrieved
         * from the registry, this means that this EncryptableProperties
         * object has been serialized and then deserialized in a different
         * classloader and virtual machine, which is an unsupported behaviour.
         */
        throw new EncryptionOperationNotPossibleException(
                "Neither a string encryptor nor a text encryptor exist " +
                "for this instance of EncryptableProperties. This is usually " +
                "caused by the instance having been serialized and then " +
                "de-serialized in a different classloader or virtual machine, " +
                "which is an unsupported behaviour (as encryptors cannot be " +
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.