/** * AES algorithm */ private PBEStringEncryptor newEncryptor(final String passphrase) { final StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); encryptor.setPassword(passphrase); encryptor.setProvider(PROVIDER); encryptor.setAlgorithm(CRYPTO_ALGO); return encryptor; } }
/** * <p> * Sets the security provider to be asked for the encryption algorithm. * The provider does not have to be registered at the security * infrastructure beforehand, and its being used here will not result in * its being registered. * </p> * <p> * If this method is called, calling {@link #setProviderName(String)} * becomes unnecessary. * </p> * <p> * If no provider name / provider is explicitly set, the default JVM * provider will be used. * </p> * * @param provider the provider to be asked for the chosen algorithm */ public void setProvider(final Provider provider) { this.firstEncryptor.setProvider(provider); }
/** * <p> * Sets the security provider to be asked for the encryption algorithm. * The provider does not have to be registered at the security * infrastructure beforehand, and its being used here will not result in * its being registered. * </p> * <p> * If this method is called, calling {@link #setProviderName(String)} * becomes unnecessary. * </p> * <p> * If no provider name / provider is explicitly set, the default JVM * provider will be used. * </p> * * @param provider the provider to be asked for the chosen algorithm */ public void setProvider(final Provider provider) { this.firstEncryptor.setProvider(provider); }
/** * <p> * Sets the security provider to be asked for the encryption algorithm. * The provider does not have to be registered at the security * infrastructure beforehand, and its being used here will not result in * its being registered. * </p> * <p> * If this method is called, calling {@link #setProviderName(String)} * becomes unnecessary. * </p> * <p> * If no provider name / provider is explicitly set, the default JVM * provider will be used. * </p> * * @param provider the provider to be asked for the chosen algorithm */ public void setProvider(final Provider provider) { this.firstEncryptor.setProvider(provider); }
/** * Sets the JCE provider to be used by the internal encryptor, * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @since 1.3 * * @param provider the JCE provider to be used */ public void setProvider(final Provider provider) { if (this.encryptorSet) { throw new EncryptionInitializationException( "An encryptor has been already set: no " + "further configuration possible on hibernate wrapper"); } final StandardPBEStringEncryptor standardPBEStringEncryptor = (StandardPBEStringEncryptor) this.encryptor; standardPBEStringEncryptor.setProvider(provider); }
StandardPBEStringEncryptor myFirstEncryptor = new StandardPBEStringEncryptor(); myFirstEncryptor.setProvider(new BouncyCastleProvider()); myFirstEncryptor.setAlgorithm("PBEWITHSHA256AND128BITAES-CBC-BC"); myFirstEncryptor.setPassword(myPassword); String myFirstEncryptedText = myFirstEncryptor.encrypt(myText);
StandardPBEStringEncryptor myFirstEncryptor = new StandardPBEStringEncryptor(); myFirstEncryptor.setProvider(new BouncyCastleProvider()); myFirstEncryptor.setAlgorithm("PBEWITHSHA256AND256BITAES-CBC-BC"); FixedStringSaltGenerator generator = new FixedStringSaltGenerator(); generator.setSalt("justAnotherSaltforGX"); //myFirstEncryptor.setSaltGenerator(new ZeroSaltGenerator()); myFirstEncryptor.setSaltGenerator(generator); myFirstEncryptor.setKeyObtentionIterations(1); String myPassword="creditCard"; myFirstEncryptor.setPassword(myPassword); String myText="Redeem Gacha "; String myFirstEncryptedText = myFirstEncryptor.encrypt(myText); System.out.println("myFirstEncryptedText AES encrypt=="+myFirstEncryptedText); System.out.println("myFirstEncryptedText AES decrypt =="+myFirstEncryptor.decrypt(myFirstEncryptedText));
/** * Lazy retrieval of the according {@link StringEncryptor} by the given * cipher UID. * * @param aCipherVersion The cipher UID for which to get the * {@link StringEncryptor}. * * @return The according {@link StringEncryptor} */ private StringEncryptor getStringEncryptor( CipherVersion aCipherVersion ) { StandardPBEStringEncryptor theStringEncryptor = _cipherUidToStringEncryptor.get( aCipherVersion.getCipher() ); if ( theStringEncryptor == null ) { synchronized ( this ) { theStringEncryptor = _cipherUidToStringEncryptor.get( aCipherVersion.getCipher() ); if ( theStringEncryptor == null ) { theStringEncryptor = new StandardPBEStringEncryptor(); theStringEncryptor.setProvider( _jceProvider ); theStringEncryptor.setAlgorithm( _jceAlgorithm ); theStringEncryptor.setPassword( aCipherVersion.getCipher() ); _cipherUidToStringEncryptor.put( aCipherVersion.getUniversalId(), theStringEncryptor ); } } } return theStringEncryptor; } }
/** * {@inheritDoc} */ @Override public void nextCipherVersion() { CipherVersion theCipherVersion = _encryptionService.next(); _stringEncryptor = new StandardPBEStringEncryptor(); _stringEncryptor.setProvider( _jceProvider ); _stringEncryptor.setAlgorithm( _jceAlgorithm ); _stringEncryptor.setPassword( theCipherVersion.getCipher() ); _cipherUid = theCipherVersion.getUniversalId(); } }