JAVA DES/CBC/PKCS5Padding加密怎么翻译成iPhone?
来源:
public static String encrypt(String src, String key) {
try {
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec dks = new DESKeySpec(key.substring(0, 8).getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(dks);
IvParameterSpec iv = new IvParameterSpec(key.substring(0, 8)
.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, securekey, iv);
StringBuilder builder = new StringBuilder();
byte[] bytes = cipher.doFinal(src.getBytes("UTF-8"));
for (byte b : bytes) {
System.out.println(b);
builder.append(b);
}
return builder.toString().toUpperCase();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
测试:
System.out.println(encrypt("1995", "ijd.dif*"));
结果:
101 113 87 110 44 8 62 -111
1011138711044862-111
上面的代码如何导入objective c - iPhone?
source:
public static String encrypt(String src, String key) {
try {
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec dks = new DESKeySpec(key.substring(0, 8).getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(dks);
IvParameterSpec iv = new IvParameterSpec(key.substring(0, 8)
.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, securekey, iv);
StringBuilder builder = new StringBuilder();
byte[] bytes = cipher.doFinal(src.getBytes("UTF-8"));
for (byte b : bytes) {
System.out.println(b);
builder.append(b);
}
return builder.toString().toUpperCase();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
Test:
System.out.println(encrypt("1995", "ijd.dif*"));
result:
101
113
87
110
44
8
62
-111
1011138711044862-111
How the code above into objective c - iPhone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论