diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/AES.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/AES.java new file mode 100644 index 0000000..4e71dff --- /dev/null +++ b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/AES.java @@ -0,0 +1,16 @@ +package org.forevery.EncryptUtils; + +/** + * Created by Forevery on 2017/9/30. + */ + +public class AES { + + public final static int CBC = 1; + public final static int CFB = 2; + public final static int ECB = 3; + public final static int OFB = 4; + + public final static String PKCS5Padding = "1"; + public final static String PKCS7Padding = "2"; +} diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/AES_BASE.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/AES_BASE.java new file mode 100644 index 0000000..6a1cf53 --- /dev/null +++ b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/AES_BASE.java @@ -0,0 +1,16 @@ +package org.forevery.EncryptUtils.Encrypt.AES; + +/** + * Created by Forevery on 2017/9/30. + */ + +public interface AES_BASE { + + public String Encrypt(String data, String password); + + public String Decrypt(String data, String password); + + public String Decrypt(String data, String password, String iv); + + public String Encrypt(String data, String password, String iv); +} diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/AES_ECB_Utils.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/AES_ECB_Utils.java new file mode 100644 index 0000000..6daf3d7 --- /dev/null +++ b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/AES_ECB_Utils.java @@ -0,0 +1,186 @@ +package org.forevery.EncryptUtils.Encrypt.AES; + +/** + * Created by Forevery on 2017/5/21. + */ + +import java.io.UnsupportedEncodingException; + +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; + +/** + * AES加密解密算法 + * + * @author long + */ +public class AES_ECB_Utils implements AES_BASE { + private final String CipherMode; + + public AES_ECB_Utils(String complement) { + StringBuilder comp = new StringBuilder(); + switch (complement) { + case "1": + comp.append("PKCS5Padding"); + break; + case "2": + comp.append("PKCS7Padding"); + break; + } + this.CipherMode = "AES/ECB/" + comp.toString(); + } + + // /** 创建密钥 **/ + private SecretKeySpec createKey(String key) { + byte[] data = null; + if (key == null) { + key = ""; + } + StringBuffer sb = new StringBuffer(16); + sb.append(key); + while (sb.length() < 16) { + sb.append("0"); + } + if (sb.length() > 16) { + sb.setLength(16); + } + + try { + data = sb.toString().getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return new SecretKeySpec(data, "AES"); + } + + + // /** 加密字节数据 **/ + private byte[] encrypt(byte[] content, String password) { + try { + SecretKeySpec key = createKey(password); + Cipher cipher = Cipher.getInstance(CipherMode); + cipher.init(Cipher.ENCRYPT_MODE, key); + byte[] result = cipher.doFinal(content); + return result; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + // /** 加密(结果为16进制字符串) **/ + public String Encrypt(String string, String password) { + byte[] data = null; + try { + data = string.getBytes("UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } + data = encrypt(data, password); + String result = byte2hex(data); + return result; + } + + // /** 解密字节数组 **/ + private byte[] decrypt(byte[] content, String password) { + try { + SecretKeySpec key = createKey(password); + Cipher cipher = Cipher.getInstance(CipherMode); + cipher.init(Cipher.DECRYPT_MODE, key); + byte[] result = cipher.doFinal(content); + return result; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + // /** 解密 **/ + public String Decrypt(String string, String password) { + byte[] data = null; + try { + data = hex2byte(string); + } catch (Exception e) { + e.printStackTrace(); + } + data = decrypt(data, password); + if (data == null) + return null; + String result = null; + try { + result = new String(data, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return result; + } + + @Override + public String Decrypt(String string, String password, String iv) { + byte[] data = null; + try { + data = hex2byte(string); + } catch (Exception e) { + e.printStackTrace(); + } + data = decrypt(data, password); + if (data == null) + return null; + String result = null; + try { + result = new String(data, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return result; + } + + @Override + public String Encrypt(String string, String password, String iv) { + byte[] data = null; + try { + data = string.getBytes("UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } + data = encrypt(data, password); + String result = byte2hex(data); + return result; + } + + private static String byte2hex(byte[] b) { + StringBuilder hs = new StringBuilder(); + String stmp; + for (int i = 0; i < b.length; i++) { + stmp = Integer.toHexString(b[i] & 0xFF).toUpperCase(); + if (stmp.length() == 1) { + hs.append("0").append(stmp); + } else { + hs.append(stmp); + } + } + return hs.toString(); + } + + /** + * 十六进制byte数组转二进制byte数组 + * hex to byte array + * + * @param hex hex string + * @return byte array + */ + private static byte[] hex2byte(String hex) + throws IllegalArgumentException { + if (hex.length() % 2 != 0) { + throw new IllegalArgumentException("invalid hex string"); + } + char[] arr = hex.toCharArray(); + byte[] b = new byte[hex.length() / 2]; + for (int i = 0, j = 0, l = hex.length(); i < l; i++, j++) { + String swap = "" + arr[i++] + arr[i]; + int byteint = Integer.parseInt(swap, 16) & 0xFF; + b[j] = new Integer(byteint).byteValue(); + } + return b; + } +} \ No newline at end of file diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/AES_Utils.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/AES_Utils.java new file mode 100644 index 0000000..25aa658 --- /dev/null +++ b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/AES_Utils.java @@ -0,0 +1,220 @@ +package org.forevery.EncryptUtils.Encrypt.AES; + +/** + * Created by Forevery on 2017/5/21. + */ + +import java.io.UnsupportedEncodingException; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +/** + * AES加密解密算法 + * + * @author long + */ +public class AES_Utils implements AES_BASE { + private final String CipherMode; + + public AES_Utils(int m, String complement) { + StringBuilder mode = new StringBuilder(); + StringBuilder comp = new StringBuilder(); + switch (m) { + case 1: + mode.append("CBC"); + break; + case 2: + mode.append("CFB"); + break; + case 4: + mode.append("OFB"); + break; + } + switch (complement) { + case "1": + comp.append("PKCS5Padding"); + break; + case "2": + comp.append("PKCS7Padding"); + break; + } + this.CipherMode = "AES/" + mode.toString() + "/" + comp.toString(); + } + + // /** 创建密钥 **/ + private SecretKeySpec createKey(String key) { + byte[] data = null; + if (key == null) { + key = ""; + } + StringBuffer sb = new StringBuffer(16); + sb.append(key); + while (sb.length() < 16) { + sb.append("0"); + } + if (sb.length() > 16) { + sb.setLength(16); + } + + try { + data = sb.toString().getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return new SecretKeySpec(data, "AES"); + } + + private IvParameterSpec createIV(String password) { + byte[] data = null; + if (password == null) { + password = ""; + } + StringBuffer sb = new StringBuffer(16); + sb.append(password); + while (sb.length() < 16) { + sb.append("0"); + } + if (sb.length() > 16) { + sb.setLength(16); + } + + try { + data = sb.toString().getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return new IvParameterSpec(data); + } + + // /** 加密字节数据 **/ + private byte[] encrypt(byte[] content, String password, String iv) { + try { + SecretKeySpec key = createKey(password); + Cipher cipher = Cipher.getInstance(CipherMode); + cipher.init(Cipher.ENCRYPT_MODE, key, createIV(iv)); + byte[] result = cipher.doFinal(content); + return result; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + // /** 加密(结果为16进制字符串) **/ + public String Encrypt(String string, String password, String iv) { + byte[] data = null; + try { + data = string.getBytes("UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } + data = encrypt(data, password, iv); + String result = byte2hex(data); + return result; + } + + // /** 解密字节数组 **/ + private byte[] decrypt(byte[] content, String password, String iv) { + try { + SecretKeySpec key = createKey(password); + Cipher cipher = Cipher.getInstance(CipherMode); + cipher.init(Cipher.DECRYPT_MODE, key, createIV(iv)); + byte[] result = cipher.doFinal(content); + return result; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + // /** 解密 **/ + public String Decrypt(String string, String password, String iv) { + byte[] data = null; + try { + data = hex2byte(string); + } catch (Exception e) { + e.printStackTrace(); + } + data = decrypt(data, password, iv); + if (data == null) + return null; + String result = null; + try { + result = new String(data, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return result; + } + + private static String byte2hex(byte[] b) { + StringBuilder hs = new StringBuilder(); + String stmp; + for (int i = 0; i < b.length; i++) { + stmp = Integer.toHexString(b[i] & 0xFF).toUpperCase(); + if (stmp.length() == 1) { + hs.append("0").append(stmp); + } else { + hs.append(stmp); + } + } + return hs.toString(); + } + + /** + * 十六进制byte数组转二进制byte数组 + * hex to byte array + * + * @param hex hex string + * @return byte array + */ + private static byte[] hex2byte(String hex) + throws IllegalArgumentException { + if (hex.length() % 2 != 0) { + throw new IllegalArgumentException("invalid hex string"); + } + char[] arr = hex.toCharArray(); + byte[] b = new byte[hex.length() / 2]; + for (int i = 0, j = 0, l = hex.length(); i < l; i++, j++) { + String swap = "" + arr[i++] + arr[i]; + int byteint = Integer.parseInt(swap, 16) & 0xFF; + b[j] = new Integer(byteint).byteValue(); + } + return b; + } + + @Override + public String Encrypt(String string, String password) { + byte[] data = null; + try { + data = string.getBytes("UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } + data = encrypt(data, password, ""); + String result = byte2hex(data); + return result; + } + + @Override + public String Decrypt(String string, String password) { + byte[] data = null; + try { + data = hex2byte(string); + } catch (Exception e) { + e.printStackTrace(); + } + data = decrypt(data, password, ""); + if (data == null) + return null; + String result = null; + try { + result = new String(data, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return result; + } +} \ No newline at end of file diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/Aes_Util.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/Aes_Util.java deleted file mode 100644 index f585eab..0000000 --- a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/Aes_Util.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.forevery.EncryptUtils.Encrypt.AES; - -/** - * Created by Forevery on 2017/5/21. - */ - -import org.forevery.EncryptUtils.Encrypt.AES.CBC.CBC_Ut; -import org.forevery.EncryptUtils.Encrypt.AES.ECB.ECB_Ut; - -/** - * AES加密解密算法 - * - * - */ -public class Aes_Util { - - public CBC_Ut CBC() { - return new CBC_Ut(); - } - - public ECB_Ut ECB() { - return new ECB_Ut(); - } - -} \ No newline at end of file diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/CBC/CBC_Ut.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/CBC/CBC_Ut.java deleted file mode 100644 index e0c5e73..0000000 --- a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/CBC/CBC_Ut.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.forevery.EncryptUtils.Encrypt.AES.CBC; - -import org.forevery.EncryptUtils.Encrypt.AES.CBC.PKCS5Padding.PKCS5Paddimg_Ulits; - -/** - * Created by Forevery on 2017/9/29. - */ - -public class CBC_Ut { - - public PKCS5Paddimg_Ulits PKCS5Paddimg() { - return new PKCS5Paddimg_Ulits(); - } -} diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/CBC/PKCS5Padding/PKCS5Paddimg_Ulits.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/CBC/PKCS5Padding/PKCS5Paddimg_Ulits.java deleted file mode 100644 index b55c03c..0000000 --- a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/CBC/PKCS5Padding/PKCS5Paddimg_Ulits.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.forevery.EncryptUtils.Encrypt.AES.CBC.PKCS5Padding; - -/** - * Created by Forevery on 2017/5/21. - * - */ - -import java.io.UnsupportedEncodingException; - -import javax.crypto.Cipher; -import javax.crypto.spec.IvParameterSpec; -import javax.crypto.spec.SecretKeySpec; - -/** - * AES加密解密算法 - * - * @author long - */ -public class PKCS5Paddimg_Ulits { - private final String CipherMode = "AES/CBC/PKCS5Padding"; - - // /** 创建密钥 **/ - private SecretKeySpec createKey(String key) { - byte[] data = null; - if (key == null) { - key = ""; - } - StringBuffer sb = new StringBuffer(16); - sb.append(key); - while (sb.length() < 16) { - sb.append("0"); - } - if (sb.length() > 16) { - sb.setLength(16); - } - - try { - data = sb.toString().getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return new SecretKeySpec(data, "AES"); - } - - private IvParameterSpec createIV(String password) { - byte[] data = null; - if (password == null) { - password = ""; - } - StringBuffer sb = new StringBuffer(16); - sb.append(password); - while (sb.length() < 16) { - sb.append("0"); - } - if (sb.length() > 16) { - sb.setLength(16); - } - - try { - data = sb.toString().getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return new IvParameterSpec(data); - } - - // /** 加密字节数据 **/ - private byte[] encrypt(byte[] content, String password, String iv) { - try { - SecretKeySpec key = createKey(password); - Cipher cipher = Cipher.getInstance(CipherMode); - cipher.init(Cipher.ENCRYPT_MODE, key, createIV(iv)); - byte[] result = cipher.doFinal(content); - return result; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - // /** 加密(结果为16进制字符串) **/ - public String Encrypt(String string, String password, String iv) { - byte[] data = null; - try { - data = string.getBytes("UTF-8"); - } catch (Exception e) { - e.printStackTrace(); - } - data = encrypt(data, password, iv); - String result = ToHexUtil.byte2hex(data); - return result; - } - - // /** 解密字节数组 **/ - private byte[] decrypt(byte[] content, String password, String iv) { - try { - SecretKeySpec key = createKey(password); - Cipher cipher = Cipher.getInstance(CipherMode); - cipher.init(Cipher.DECRYPT_MODE, key, createIV(iv)); - byte[] result = cipher.doFinal(content); - return result; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - // /** 解密 **/ - public String Decrypt(String string, String password, String iv) { - byte[] data = null; - try { - data = ToHexUtil.hex2byte(string); - } catch (Exception e) { - e.printStackTrace(); - } - data = decrypt(data, password, iv); - if (data == null) - return null; - String result = null; - try { - result = new String(data, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return result; - } -} \ No newline at end of file diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/CBC/PKCS5Padding/ToHexUtil.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/CBC/PKCS5Padding/ToHexUtil.java deleted file mode 100644 index d2181d8..0000000 --- a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/CBC/PKCS5Padding/ToHexUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.forevery.EncryptUtils.Encrypt.AES.CBC.PKCS5Padding; - -/** - * Created by Forevery on 2017/5/22. - * - */ - -class ToHexUtil { - - public static String byte2hex(byte[] b) { - StringBuilder hs = new StringBuilder(); - String stmp; - for (int i = 0; i < b.length; i++) { - stmp = Integer.toHexString(b[i] & 0xFF).toUpperCase(); - if (stmp.length() == 1) { - hs.append("0").append(stmp); - } else { - hs.append(stmp); - } - } - return hs.toString(); - } - - /** - * 十六进制byte数组转二进制byte数组 - * hex to byte array - * - * @param hex hex string - * @return byte array - */ - public static byte[] hex2byte(String hex) - throws IllegalArgumentException { - if (hex.length() % 2 != 0) { - throw new IllegalArgumentException("invalid hex string"); - } - char[] arr = hex.toCharArray(); - byte[] b = new byte[hex.length() / 2]; - for (int i = 0, j = 0, l = hex.length(); i < l; i++, j++) { - String swap = "" + arr[i++] + arr[i]; - int byteint = Integer.parseInt(swap, 16) & 0xFF; - b[j] = new Integer(byteint).byteValue(); - } - return b; - } -} diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/ECB/ECB_Ut.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/ECB/ECB_Ut.java deleted file mode 100644 index cbef00b..0000000 --- a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/ECB/ECB_Ut.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.forevery.EncryptUtils.Encrypt.AES.ECB; - -import org.forevery.EncryptUtils.Encrypt.AES.ECB.NoPadding.NoPadding_Utils; - -/** - * Created by Forevery on 2017/9/29. - */ - -public class ECB_Ut { - - public NoPadding_Utils NoPadding() { - return new NoPadding_Utils(); - } -} diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/ECB/NoPadding/NoPadding_Utils.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/ECB/NoPadding/NoPadding_Utils.java deleted file mode 100644 index 02bca52..0000000 --- a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/Encrypt/AES/ECB/NoPadding/NoPadding_Utils.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.forevery.EncryptUtils.Encrypt.AES.ECB.NoPadding; - -import static org.forevery.EncryptUtils.Encrypt.Utils.base64Decode; -import static org.forevery.EncryptUtils.Encrypt.Utils.base64Encode; -import static org.forevery.EncryptUtils.Encrypt.Utils.bytes2HexString; -import static org.forevery.EncryptUtils.Encrypt.Utils.desTemplate; -import static org.forevery.EncryptUtils.Encrypt.Utils.hexString2Bytes; - -/** - * Created by Forevery on 2017/9/29. - */ - -public class NoPadding_Utils { - /** - * AES转变 - *

法算法名称/加密模式/填充方式

- *

加密模式有:电子密码本模式ECB、加密块链模式CBC、加密反馈模式CFB、输出反馈模式OFB

- *

填充方式有:NoPadding、ZerosPadding、PKCS5Padding

- */ - public String AES_Transformation = "AES/ECB/NoPadding"; - private final String AES_Algorithm = "AES"; - - - /** - * AES加密后转为Base64编码 - * - * @param data 明文 - * @param key 16、24、32字节秘钥 - * @return Base64密文 - */ - public byte[] Encrypt_Base64(final byte[] data, final byte[] key) { - return base64Encode(Decrypt_Byte(data, key)); - } - - /** - * AES加密后转为16进制 - * - * @param data 明文 - * @param key 16、24、32字节秘钥 - * @return 16进制密文 - */ - public String Encrypt(final byte[] data, final byte[] key) { - return bytes2HexString(Decrypt_Byte(data, key)); - } - - /** - * AES加密 - * - * @param data 明文 - * @param key 16、24、32字节秘钥 - * @return 密文 - */ - public byte[] Encrypt_Byte(final byte[] data, final byte[] key) { - return desTemplate(data, key, AES_Algorithm, AES_Transformation, true); - } - - /** - * AES解密Base64编码密文 - * - * @param data Base64编码密文 - * @param key 16、24、32字节秘钥 - * @return 明文 - */ - public byte[] Decrypt(final byte[] data, final byte[] key) { - return Decrypt_Byte(base64Decode(data), key); - } - - /** - * AES解密16进制密文 - * - * @param data 16进制密文 - * @param key 16、24、32字节秘钥 - * @return 明文 - */ - public byte[] Decrypt(final String data, final byte[] key) { - return Decrypt_Byte(hexString2Bytes(data), key); - } - - /** - * AES解密 - * - * @param data 密文 - * @param key 16、24、32字节秘钥 - * @return 明文 - */ - public byte[] Decrypt_Byte(final byte[] data, final byte[] key) { - return desTemplate(data, key, AES_Algorithm, AES_Transformation, false); - } - -} diff --git a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/EncryptUtils.java b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/EncryptUtils.java index e9aeed8..2563ccb 100644 --- a/EncryptUtils/src/main/java/org/forevery/EncryptUtils/EncryptUtils.java +++ b/EncryptUtils/src/main/java/org/forevery/EncryptUtils/EncryptUtils.java @@ -1,6 +1,8 @@ package org.forevery.EncryptUtils; -import org.forevery.EncryptUtils.Encrypt.AES.Aes_Util; +import org.forevery.EncryptUtils.Encrypt.AES.AES_BASE; +import org.forevery.EncryptUtils.Encrypt.AES.AES_ECB_Utils; +import org.forevery.EncryptUtils.Encrypt.AES.AES_Utils; import org.forevery.EncryptUtils.Encrypt.DES.DES_Utils; import org.forevery.EncryptUtils.Encrypt.HmacMD5.HmacMD5_Utils; import org.forevery.EncryptUtils.Encrypt.HmacSHA1.HmacSHA1_Utils; @@ -31,8 +33,9 @@ private EncryptUtils() { /** * AES 加密 */ - public static Aes_Util AES() { - return new Aes_Util(); + public static AES_BASE AES(int mode, String complement) { + if (mode == AES.ECB) return new AES_ECB_Utils(complement); + return new AES_Utils(mode, complement); } /** diff --git a/README.md b/README.md index d40d7db..38d2c6c 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,18 @@ EncryptUtils.AES()...... : AES加密/解密 * ### AES加密解密相关 ``` -目前只支持CBC的PKCS5Paddimg模式,ECB的NoPaddimg模式 +算法模式: + AES.CBC : CBC模式 + AES.CFB : CFB模式 + AES.ECB : ECB模式 + AES.OFB : OFB模式 +补码方式: + AES.PKCS5Padding : PKCS5Padding方式 + AES.PKCS7Padding : PKCS7Padding方式 + + EncryptUtils.AES(int mode,String complement)........ +例: + EncryptUtils.AES(AES.CBC,AES.PKCS5Padding)........ ``` ## Download @@ -40,7 +51,7 @@ allprojects { compile: ``` dependencies { - compile 'com.github.Forevery1:EncryptUtils:1.1' + compile 'com.github.Forevery1:EncryptUtils:1.2' } ``` diff --git a/app/src/main/java/org/forevery/Deom/Main_Activity.java b/app/src/main/java/org/forevery/Deom/Main_Activity.java index 46aa579..e7f9cec 100644 --- a/app/src/main/java/org/forevery/Deom/Main_Activity.java +++ b/app/src/main/java/org/forevery/Deom/Main_Activity.java @@ -9,6 +9,5 @@ public class Main_Activity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - } }