Package org.jasypt.exceptions

Examples of org.jasypt.exceptions.EncryptionInitializationException


           
            try {
           
                // Password cannot be null.
                if (this.password == null) {
                    throw new EncryptionInitializationException(
                            "Password not set for Password Based Encryptor");
                }
               
                // Normalize password to NFC form
                this.password = Normalizer.normalizeToNfc(this.password);
               
                /*
                 * Encryption and decryption Ciphers are created the usual way.
                 */
                PBEKeySpec pbeKeySpec =
                    new PBEKeySpec(this.password.toCharArray());
               
                if (this.provider != null) {
                   
                    SecretKeyFactory factory =
                        SecretKeyFactory.getInstance(
                                this.algorithm,
                                this.provider);
                   
                    this.key = factory.generateSecret(pbeKeySpec);
                   
                    this.encryptCipher =
                        Cipher.getInstance(this.algorithm, this.provider);
                    this.decryptCipher =
                        Cipher.getInstance(this.algorithm, this.provider);
                   
                } else if (this.providerName != null) {
                   
                    SecretKeyFactory factory =
                        SecretKeyFactory.getInstance(
                                this.algorithm,
                                this.providerName);
                   
                    this.key = factory.generateSecret(pbeKeySpec);
                   
                    this.encryptCipher =
                        Cipher.getInstance(this.algorithm, this.providerName);
                    this.decryptCipher =
                        Cipher.getInstance(this.algorithm, this.providerName);
                   
                } else {
                   
                    SecretKeyFactory factory =
                        SecretKeyFactory.getInstance(this.algorithm);
                   
                    this.key = factory.generateSecret(pbeKeySpec);
                   
                    this.encryptCipher = Cipher.getInstance(this.algorithm);
                    this.decryptCipher = Cipher.getInstance(this.algorithm);
                   
                }

            } catch (EncryptionInitializationException e) {
                throw e;
            } catch (Throwable t) {
                throw new EncryptionInitializationException(t);
            }
           

            // The salt size for the chosen algorithm is set to be equal
            // to the algorithm's block size (if it is a block algorithm).
View Full Code Here


    public void setKeyObtentionIterations(String keyObtentionIterations) {
        if (keyObtentionIterations != null) {
            try {
                this.keyObtentionIterations = new Integer(keyObtentionIterations);
            } catch (NumberFormatException e) {
                throw new EncryptionInitializationException(e);
            }
        } else {
            this.keyObtentionIterations = null;
        }
    }
View Full Code Here

                Class saltGeneratorClass =
                    Thread.currentThread().getContextClassLoader().loadClass(saltGeneratorClassName);
                this.saltGenerator =
                    (SaltGenerator) saltGeneratorClass.newInstance();
            } catch (Exception e) {
                throw new EncryptionInitializationException(e);
            }
        } else {
            this.saltGenerator = null;
        }
    }
View Full Code Here

            try {
                Class providerClass =
                    Thread.currentThread().getContextClassLoader().loadClass(providerClassName);
                this.provider = (Provider) providerClass.newInstance();
            } catch (Exception e) {
                throw new EncryptionInitializationException(e);
            }
        } else {
            this.provider = null;
        }
    }
View Full Code Here

           
            if ((paramAlgorithm != null) ||
                (paramPassword != null) ||
                (paramKeyObtentionIterations != null)) {
               
                throw new EncryptionInitializationException(
                        "If \"" + ParameterNaming.ENCRYPTOR_NAME +
                        "\" is specified, none of \"" +
                        ParameterNaming.ALGORITHM + "\", \"" +
                        ParameterNaming.PASSWORD + "\" or \"" +
                        ParameterNaming.KEY_OBTENTION_ITERATIONS + "\" " +
                        "can be specified");
               
            }
            this.encryptorName = paramEncryptorName;
            this.useEncryptorName = true;
           
        } else if ((paramPassword != null)) {

            this.password = paramPassword;
           
            if (paramAlgorithm != null) {
                this.algorithm = paramAlgorithm;
            }
           
            if (paramKeyObtentionIterations != null) {

                try {
                    this.keyObtentionIterations =
                        new Integer(
                                Integer.parseInt(paramKeyObtentionIterations));
                } catch (NumberFormatException e) {
                    throw new EncryptionInitializationException(
                            "Value specified for \"" +
                            ParameterNaming.KEY_OBTENTION_ITERATIONS +
                            "\" is not a valid integer");
                }
               
            }
           
        } else {
           
            throw new EncryptionInitializationException(
                    "If \"" + ParameterNaming.ENCRYPTOR_NAME +
                    "\" is not specified, then \"" +
                    ParameterNaming.PASSWORD + "\" (and optionally \"" +
                    ParameterNaming.ALGORITHM + "\" and \"" +
                    ParameterNaming.KEY_OBTENTION_ITERATIONS + "\") " +
View Full Code Here

                HibernatePBEEncryptorRegistry registry =
                    HibernatePBEEncryptorRegistry.getInstance();
                PBEByteEncryptor pbeEncryptor =
                    registry.getPBEByteEncryptor(this.encryptorName);
                if (pbeEncryptor == null) {
                    throw new EncryptionInitializationException(
                            "No big integer encryptor registered for hibernate " +
                            "with name \"" + this.encryptorName + "\"");
                }
                this.encryptor = pbeEncryptor;
               
View Full Code Here

    public void setIterations(String iterations) {
        if (iterations != null) {
            try {
                this.iterations = new Integer(iterations);
            } catch (NumberFormatException e) {
                throw new EncryptionInitializationException(e);
            }
        } else {
            this.iterations = null;
        }
    }
View Full Code Here

    public void setSaltSizeBytes(String saltSizeBytes) {
        if (saltSizeBytes != null) {
            try {
                this.saltSizeBytes = new Integer(saltSizeBytes);
            } catch (NumberFormatException e) {
                throw new EncryptionInitializationException(e);
            }
        } else {
            this.saltSizeBytes = null;
        }
    }
View Full Code Here

                Class saltGeneratorClass =
                    Thread.currentThread().getContextClassLoader().loadClass(saltGeneratorClassName);
                this.saltGenerator =
                    (SaltGenerator) saltGeneratorClass.newInstance();
            } catch (Exception e) {
                throw new EncryptionInitializationException(e);
            }
        } else {
            this.saltGenerator = null;
        }
    }
View Full Code Here

            try {
                Class providerClass =
                    Thread.currentThread().getContextClassLoader().loadClass(providerClassName);
                this.provider = (Provider) providerClass.newInstance();
            } catch (Exception e) {
                throw new EncryptionInitializationException(e);
            }
        } else {
            this.provider = null;
        }
    }
View Full Code Here

TOP

Related Classes of org.jasypt.exceptions.EncryptionInitializationException

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.