Reputation: 311
Im newbee in terms of encryption algho im trying to create SHA-512 to convert this variable data into SHA-512 so i can pass it in server in my project any help will be appreciated.
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);
Upvotes: 5
Views: 5389
Reputation: 1159
You can use MessageDigest in java for encryption
Descripction - https://developer.android.com/reference/java/security/MessageDigest.html
Supported Algorithm
Try this code
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);
}
Upvotes: 5
Reputation: 2455
You could use this online converter for text to SHA512, it is good one.
If you want to use it in Android use SALT for that something like this: this code will give you the required output needed from text to sha512
Upvotes: 1