对方接口需要数据加密,java代码如下:
public class AESUtil {
public final static String CHART_DEFAULT="UTF-8" ;
private static String IVRANDOM = "0123456789ABEDEF";
public static String enAES(String security,String key){
try {
byte[] content = security.getBytes(CHART_DEFAULT);
byte[] aeskeys = key.getBytes(CHART_DEFAULT);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
IvParameterSpec sp= new IvParameterSpec(IVRANDOM.getBytes(CHART_DEFAULT));
SecretKeySpec spec = new SecretKeySpec(aeskeys,"AES");
cipher.init(Cipher.ENCRYPT_MODE, spec,sp);
byte[] context = cipher.doFinal(content);
return Base64.encodeBase64String(context);
} catch (Exception e){
}
return null;
}
public static void main(String[] args) {
String code = enAES("{\"text\":\"1234\"}","123456781234567812345678");
System.out.println("加密后的密文:"+code);
}
}
php 里用openssl_encrypt 试了很多种都不行,对应的php应该怎么写呢,帮帮忙,谢谢!