Im newbee在加密方面algho我试图创建SHA-512将这个可变数据转换成SHA-512所以我可以在我的项目服务器中传递它任何帮助将不胜感激。
if (pojo.getAmount() != null && !pojo.getAmount().equals("")) {
//Data variables needs to convert in SHA-512
hsString = merchantID + "" + "" + req_id + "" + ip_address + ""
+ notication_url + "" + package_name + "" + firstname + "" + lastname + ""
+ middlename + "" + address1 + "" + address2 + "" + city + "" + state + ""
+ country + "" + zip + "" + email + "" + phone + "" + client_ip + "" + ""
+ cost + "" + currency + "" + secur3d + "" + merchantKey;
//base64string one of the transaction parameters
base64_enconded = Base64.encodeToString(hsString.getBytes(),Base64.DEFAULT);
答案 0 :(得分:2)
您可以在java中使用 MessageDigest 进行加密
描述 - https://developer.android.com/reference/java/security/MessageDigest.html
支持的算法
试试此代码
try{
MessageDigest md = MessageDigest.getInstance("SHA-512");
byte[] data = md.digest(hsString.getBytes());
StringBuilder sb = new StringBuilder();
for(int i=0;i<data.length;i++)
{
sb.append(Integer.toString((data[i] & 0xff) + 0x100, 16).substring(1));
}
System.out.println(sb);
}
catch(Exception e)
{
System.out.println(e);
}
答案 1 :(得分:1)