实在是没辙了。别人给的java代码。不知道怎么翻译成php
public static String encrypt(String content, String password) {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
int blockSize = cipher.getBlockSize();
byte[] dataBytes = content.getBytes();
int plaintextLength = dataBytes.length;
if (plaintextLength % blockSize != 0) {
plaintextLength = plaintextLength
+ (blockSize - (plaintextLength % blockSize));
}
byte[] plaintext = new byte[plaintextLength];
System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length); SecretKeySpec keyspec = new SecretKeySpec(password.getBytes(),
"AES");
IvParameterSpec ivspec = new IvParameterSpec(password.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
byte[] encrypted = cipher.doFinal(plaintext); return parseByte2HexStr(encrypted); } catch (Exception e) {
e.printStackTrace();
} return null;
}