java-如何应用SHA-512?
作者:互联网
在加密方面,我是newbee.我试图创建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);
解决方法:
您可以在Java中使用MessageDigest进行加密
描述-https://developer.android.com/reference/java/security/MessageDigest.html
支持的算法
> MD2
> MD5
> SHA-1
> SHA-256
> SHA-384
> SHA-512
试试这个代码
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);
}
标签:sha512,java,android 来源: https://codeday.me/bug/20191109/2011581.html