@@ -0,0 +1,3299 @@
+package xyz.x0156.aes.util;%0A%0Aimport java.security.InvalidAlgorithmParameterException;%0Aimport java.security.InvalidKeyException;%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.security.spec.InvalidKeySpecException;%0Aimport java.security.spec.KeySpec;%0A%0Aimport javax.crypto.BadPaddingException;%0Aimport javax.crypto.Cipher;%0Aimport javax.crypto.IllegalBlockSizeException;%0Aimport javax.crypto.SecretKey;%0Aimport javax.crypto.SecretKeyFactory;%0Aimport javax.crypto.spec.IvParameterSpec;%0Aimport javax.crypto.spec.PBEKeySpec;%0Aimport javax.crypto.spec.SecretKeySpec;%0A%0Aimport org.apache.commons.codec.DecoderException;%0Aimport org.apache.commons.codec.binary.Base64;%0Aimport org.apache.commons.codec.binary.Hex;%0A/**%0A * %0A * @author x0156%0A */%0Apublic class AesUtil %7B%0A%0A    private final String salt = %2256d7c4c857d73be3a046af1c1a3eb444%22;%0A    private final String iv = %22efc29528417b31a006d0aec4df640a62%22;%0A%0A    private final int keySize;%0A    private final int iterationCount;%0A    private final Cipher cipher;%0A%0A    public AesUtil(int keySize, int iterationCount) throws Exception %7B%0A        this.keySize = keySize;%0A        this.iterationCount = iterationCount;%0A        cipher = Cipher.getInstance(%22AES/CBC/PKCS5Padding%22);%0A%0A    %7D%0A%0A    public String encrypt(String passphrase, String plaintext) throws Exception %7B%0A        return encrypt(this.salt, this.iv, passphrase, plaintext);%0A    %7D%0A%0A    public String encrypt(String salt, String iv, String passphrase, String plaintext) throws Exception %7B%0A        SecretKey key = generateKey(salt, passphrase);%0A        byte%5B%5D encrypted = doFinal(Cipher.ENCRYPT_MODE, key, iv, plaintext.getBytes(%22UTF-8%22));%0A        return encode(encrypted);%0A    %7D%0A%0A    public String decrypt(String passphrase, String ciphertext) throws Exception %7B%0A        return decrypt(this.salt, this.iv, passphrase, ciphertext);%0A    %7D%0A%0A    public String decrypt(String salt, String iv, String passphrase, String ciphertext) throws Exception %7B%0A%0A        SecretKey key = generateKey(salt, passphrase);%0A        byte%5B%5D decrypted = doFinal(Cipher.DECRYPT_MODE, key, iv, decode(ciphertext));%0A        return new String(decrypted, %22UTF-8%22);%0A%0A    %7D%0A%0A    private byte%5B%5D doFinal(int encryptMode, SecretKey key, String iv, byte%5B%5D bytes) throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException %7B%0A        cipher.init(encryptMode, key, new IvParameterSpec(toHex(iv)));%0A        return cipher.doFinal(bytes);%0A    %7D%0A%0A    private SecretKey generateKey(String salt, String passphrase) throws NoSuchAlgorithmException, InvalidKeySpecException %7B%0A        SecretKeyFactory factory = SecretKeyFactory.getInstance(%22PBKDF2WithHmacSHA1%22);%0A        KeySpec spec = new PBEKeySpec(passphrase.toCharArray(), toHex(salt), iterationCount, keySize);%0A        SecretKey key = new SecretKeySpec(factory.generateSecret(spec).getEncoded(), %22AES%22);%0A        return key;%0A    %7D%0A%0A    private static String encode(byte%5B%5D bytes) %7B%0A        return Base64.encodeBase64String(bytes);%0A    %7D%0A%0A    private static byte%5B%5D decode(String str) %7B%0A        return Base64.decodeBase64(str);%0A    %7D%0A%0A    private static byte%5B%5D toHex(String str) %7B%0A        try %7B%0A            return Hex.decodeHex(str.toCharArray());%0A        %7D catch (DecoderException e) %7B%0A            throw new IllegalStateException(e);%0A        %7D%0A    %7D%0A%0A%7D%0A

Create AesUtil.java