Home > Backend Development > PHP Tutorial > aes加密java解密有关问题

aes加密java解密有关问题

WBOY
Release: 2016-06-13 10:13:46
Original
1082 people have browsed it

aes加密java解密问题
public static String Encrypt(String sSrc, String sKey) throws Exception {
byte[] raw = sKey.getBytes();
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
IvParameterSpec iv = new IvParameterSpec("0102030405060708".getBytes());
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
byte[] encrypted = cipher.doFinal(sSrc.getBytes());

return new BASE64Encoder().encode(encrypted);
}

String cKey = "1234567890";
// 需要加密的字串
String cSrc = "testtest";
System.out.println(cSrc);
// 加密
long lStart = System.currentTimeMillis();
String enString = AES.Encrypt(cSrc, cKey);
System.out.println("加密后的字串是:" + enString);

用PHP实现java的这个函数,加密后的字符串和java端不一样。
请帮我用PHP来实现java的这个加密函数,

------解决方案--------------------
不要假定人家都有 java 环境,并能正确执行你的代码
你至少需要给出 3 组原文和密文

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template