How to apply SHA-512?
Asked Answered
S

2

5

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);
Stroboscope answered 17/4, 2018 at 3:54 Comment(4)
You can use JNA/JNI with libsodium to do so download.libsodium.org/doc/advanced/sha-2_hash_function.htmlAubyn
did you check this one, mkyong.com/java/java-sha-hashing-exampleRufena
How about OpenSSL, you can have a look at it.Quinsy
yeah i already check that thank you @Rufena and Harsha JKStroboscope
I
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); 
 }
Ivy answered 17/4, 2018 at 4:18 Comment(0)
W
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

Wivina answered 17/4, 2018 at 4:3 Comment(1)
hi what i mean is programmatically to convert variable in hash(SHA-512) not a tool like the link you give , thank youStroboscope

© 2022 - 2024 — McMap. All rights reserved.