Enable Android and Java to decrypt each other
Perfect support for Chinese
Cross-platform This implementation
It's still a principle.
Do not use default implementations for parameters
Otherwise difficult to exchange
The core functions are as follows, both Android and Java (datapassword length is 16)
[Java]View plain copy public static final String Vipara = "0102030405060708"; public static final String BM = "GBK";
[Java] View plain copy public static string encrypt (string datapassword, string cleartext) throws Exception { ivparameterspec zeroiv = new ivparameterspec (VIPARA.getBytes ()); secretkeyspec key = new secretkeyspec ( Datapassword.getbytes (), "AES"); Cipher cipher = Cipher.getinstance ("aes/cbc/pkcs5padding"); cipher.init (Cipher.ENCRYPT_MODE ,  KEY, ZEROIV); byte[] encryptedData = Cipher.dofinal (Cleartext.getbytes (BM)); return Base64.encode (EncryptedData); } Public static string decrypt ( string datapassword, string encrypted) throws Exception { byte[] bytemi = base64.decode (encrypted); ivparameterspec zeroiv = new ivparameterspec (Vipara.getbytes ()); secretkeyspec key = new secretkeyspec (DataPassword.getBytes (), "AES "); cipher cipher = cipher.getinstance (" AES/CBC/PKCS5Padding "); cipher.init (CIPHER.DECRYPT_MODE, KEY, ZEROIV); byte[] decrypteddata = cipher.dofinal (byteMi); return new string (DECRYPTEDDATA,BM); }
Base64 from the Internet to find the tool class
[Java] view plain copy package Com.bao; Import Java.io.ByteArrayOutputStream; Import java.io.IOException; Import Java.io.OutputStream; public class Base64 {private static final char[] Legalchars = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz 0123456789+/". ToCharArray (); /** * data[] Code * @param data * @return/public static String encode (byte[] data) {