//加密
public static byte[] encrypt(byte[] content,String password){
try {
// 创建秘钥
SecretKeySpec secretKeySpec = new SecretKeySpec(password.getBytes(), "ECB");
// 创建密码器
Cipher cipher = Cipher.getInstance("ARC4");
// 初始化加密器
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
// 加密
return cipher.doFinal(content);
}catch (Exception e){
e.printStackTrace();
}
return null;
}
//解密
public static byte[] decrypt(byte[] content, String password) {
try {
// 创建秘钥
SecretKeySpec key = new SecretKeySpec(password.getBytes(), "ECB");
// 创建密码器
Cipher cipher = Cipher.getInstance("ARC4");
// 初始化解密器
cipher.init(Cipher.DECRYPT_MODE, key);
// 解密
return cipher.doFinal(content);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}