/**
 * The MIT License
 *
 * Copyright (C) 2015 Asterios Raptis
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package de.alpharogroup.crypto.simple;

import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.util.Base64;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;

import de.alpharogroup.check.Check;
import de.alpharogroup.crypto.CryptConst;
import de.alpharogroup.crypto.api.Cryptor;
import de.alpharogroup.crypto.api.StringEncryptor;
import lombok.AccessLevel;
import lombok.Getter;

/**
 * The class {@link SimpleEncryptor} is a simple {@link StringEncryptor} implementation.
 *
 * @author Asterios Raptis
 * @version 1.0
 */
public class SimpleEncryptor implements StringEncryptor, Cryptor
{

	/**
	 * The Cipher object.
	 */
	private Cipher cipher;

	/**
	 * The flag initialized that indicates if the cypher is initialized for decryption.
	 *
	 * @return true, if is initialized
	 */
	@Getter(value = AccessLevel.PRIVATE)
	private boolean initialized;

	/**
	 * The private key.
	 */
	@Getter
	private final String privateKey;

	/**
	 * Instantiates a new {@link SimpleEncryptor} with the given private key.
	 *
	 * @param privateKey
	 *            The private key.
	 */
	public SimpleEncryptor(final String privateKey)
	{
		Check.get().notEmpty(privateKey, "privateKey");
		this.privateKey = privateKey;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String encrypt(final String string)
		throws UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException,
		InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException,
		NoSuchPaddingException, InvalidAlgorithmParameterException
	{
		initialize();
		final byte[] utf8 = string.getBytes(CryptConst.ENCODING);
		final byte[] encrypt = this.cipher.doFinal(utf8);
		final String encrypted = Base64.getEncoder().encodeToString(encrypt);
		return encrypted;
	}

	/**
	 * Initializes the {@link SimpleEncryptor} object.
	 *
	 * @throws InvalidAlgorithmParameterException
	 *             is thrown if initialization of the cypher object fails.
	 * @throws NoSuchPaddingException
	 *             is thrown if instantiation of the cypher object fails.
	 * @throws InvalidKeySpecException
	 *             is thrown if generation of the SecretKey object fails.
	 * @throws NoSuchAlgorithmException
	 *             is thrown if instantiation of the SecretKeyFactory object fails.
	 * @throws InvalidKeyException
	 *             is thrown if initialization of the cypher object fails.
	 */
	private void initialize() throws NoSuchAlgorithmException, InvalidKeySpecException,
		NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
	{
		if (!isInitialized())
		{
			final KeySpec keySpec;
			if (this.getPrivateKey() != null)
			{
				keySpec = new PBEKeySpec(this.getPrivateKey().toCharArray());
			}
			else
			{
				keySpec = new PBEKeySpec(CryptConst.PRIVATE_KEY.toCharArray());
			}
			final SecretKeyFactory factory = SecretKeyFactory
				.getInstance(CryptConst.PBE_WITH_MD5_AND_DES);
			final SecretKey key = factory.generateSecret(keySpec);
			this.cipher = Cipher.getInstance(key.getAlgorithm());
			final AlgorithmParameterSpec paramSpec = new PBEParameterSpec(CryptConst.SALT,
				CryptConst.ITERATIONCOUNT);
			this.cipher.init(newOperationMode(), key, paramSpec);
			initialized = true;
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int newOperationMode()
	{
		return Cipher.ENCRYPT_MODE;
	}
}

@@ -2062,16 +2062,39 @@
 .Getter;
+%0Aimport lombok.NonNull;
 %0A%0A/**%0A *
@@ -2804,24 +2804,33 @@
 yptor(final 
+@NonNull 
 String priva
@@ -2843,58 +2843,8 @@
 %0A%09%7B%0A
-%09%09Check.get().notEmpty(privateKey, %22privateKey%22);%0A
 %09%09th
@@ -4246,63 +4246,8 @@
 pec 
-keySpec;%0A%09%09%09if (this.getPrivateKey() != null)%0A%09%09%09%7B%0A%09%09%09%09
 keyS
@@ -4311,95 +4311,8 @@
 %0A%09%09%09
-%7D%0A%09%09%09else%0A%09%09%09%7B%0A%09%09%09%09keySpec = new PBEKeySpec(CryptConst.PRIVATE_KEY.toCharArray());%0A%09%09%09%7D
 %0A%09%09%09

Update SimpleEncryptor.java