AES Encrypt public string Encrypt_aes (string source, String key) throws Exception {if (key = = null) {return null;} Determine if key is a 16-bit if (key.length ()! =) {return null;} Byte[] raw = key.getbytes (); Secretkey KeySpec = new Secretkeyspec (Raw, "AES");//algorithm/mode/complement mode cipher cipher = cipher.getinstance ("aes/cbc/pkcs5padding ");//using CBC mode, you need a vector that increases the strength of the algorithm Ivparameterspec IV = new Ivparameterspec (" 0102030405060708 ". GetBytes ()); Cipher.init ( Cipher.encrypt_mode, KeySpec, iv); byte[] encrypted = Cipher.dofinal (Source.getbytes ()); return base64.encodetostring ( encrypted, base64.default);} AES Decrypt public string Decrypt_aes (string resource, String key) throws Exception {try {///determines if key is correct if (key = = null) {return null;} if (Key.length ()! =) {return null;} Byte[] Raw = key.getbytes ("ASCII"); Secretkey KeySpec = new Secretkeyspec (Raw, "AES");//algorithm/mode/complement mode cipher cipher = cipher.getinstance ("aes/cbc/pkcs5padding ");//using CBC mode, you need a vector that increases the strength of the algorithm Ivparameterspec IV = new Ivparameterspec (" 0102030405060708 ". GetBytes ()); Cipher.init (Cipher.encrypt_mode, KeySpec, iv); byte[] encrypted1 = Base64.decode (resource, base64.default); try {byte[] original = Cipher.dofinal (encrypted1); String originalstring = new String (original); return originalstring;} catch (Exception e) {return null;}} catch (Exception e) {return null;}}
Rabbit--aes encryption, decryption algorithm