java aes加密方式转换成PHP的,请指教

有一段Java的aes加密方式,想转换成PHP7的 请问该怎么转换呢

public static String encrypt(String str, String secretKey) {

try {

// 加密

Cipher cipher = Cipher.getInstance(AES);

cipher.init(Cipher.ENCRYPT_MODE, getKey(secretKey));

byte[] result = cipher.doFinal(str.getBytes());

// return Hex.encodeHexString(result);

//通过Base64转码返回

return Base64.encodeBase64String(result);

} catch (Exception e) {

logger.error(e.getMessage(), e);

}

return "";

}

private static Key getKey(String secretKey) {

try {

// 生成KEY ,AES 要求密钥长度为 128

KeyGenerator keyGenerator = KeyGenerator.getInstance(AES);

SecureRandom secureRandom = SecureRandom.getInstance(SHA1PRNG);

secureRandom.setSeed(secretKey.getBytes());

keyGenerator.init(128, secureRandom);

SecretKey secretKey1 = keyGenerator.generateKey();

byte[] byteKey = secretKey1.getEncoded();

return new SecretKeySpec(byteKey, AES);

} catch (Exception e) {

logger.error(e.getMessage(), e);

return null;

}

}

以上是 java aes加密方式转换成PHP的,请指教 的全部内容, 来源链接: utcz.com/p/944178.html

回到顶部