4

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);
Shan
  • 301
  • 1
  • 3
  • 14

2 Answers2

5

You can use MessageDigest in java for encryption

Descripction - https://developer.android.com/reference/java/security/MessageDigest.html

Supported Algorithm

  1. MD2
  2. MD5
  3. SHA-1
  4. SHA-256
  5. SHA-384
  6. SHA-512

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); 
 }
Rohit Chauhan
  • 1,119
  • 1
  • 12
  • 30
1

You could use this online converter for text to SHA512, it is good one.

link

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

Example

Prashant Abdare
  • 2,175
  • 14
  • 24
  • hi what i mean is programmatically to convert variable in hash(SHA-512) not a tool like the link you give , thank you – Shan Apr 17 '18 at 04:08