* AES加密(AES/ECB/PKCS5Padding)key UTF8 取前十六個字節
*
* @param str
* @return 加密後base64字符串
*/
public static String getAESdata(String sSrc) throws Exception {
if (sKey == null) {
return null;
}
byte[] raw = new byte[16];
byte[] bytekeys = sKey.getBytes("utf-8");
int iv = bytekeys.length;
if (iv > 16)
iv = 16;
System.arraycopy(bytekeys, 0, raw, 0, iv);
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");// "算法/模式/補碼方式"
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
return new Base64().encodeToString(encrypted);// 此處使用BASE64做轉碼功能
}
sSrc 需要加密的參數