* ** AES encryption ** @ paramkey * key Information * @ paramcontent * information to be encrypted * publicstaticbyte [] encodeAES (byte [] key, byte [] content) throwsException {not a multiple of 16, complement intbase16; if (key. length % base! 0) {intgroupskey. lengthbase + (key. length %... phpjavaaes
/**
* AES encryption
*
* @ Param key
* Key Information
* @ Param content
* Information to be encrypted
*/
Public static byte [] encodeAES (byte [] key, byte [] content) throws Exception {
// Not a multiple of 16, complement
Int base = 16;
If (key. length % base! = 0 ){
Int groups = key. length/base + (key. length % base! = 0? 1: 0 );
Byte [] temp = new byte [groups * base];
Arrays. fill (temp, (byte) 0 );
System. arraycopy (key, 0, temp, 0, key. length );
Key = temp;
}
SecretKey secretKey = new SecretKeySpec(key, "AES"); IvParameterSpec iv = new IvParameterSpec(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv); byte[] tgtBytes = cipher.doFinal(content); return tgtBytes;}