Reply
Highlighted
Member
Posts: 2
Registered: ‎04-13-2020

SHA-512 hash mismatch - Java

Hi,

SHA-512 hash mismatch when we enter special characters in the hosted payment page fields such as Address.

 

String xAddress = "712 Savoie �Rd";

x_SHA2_Hash=EB4E5F5BED46568B8BD7F7577BEE19DDAC9616B16613E1CFAEA5E606ABA6496A5150289FF8D98AA3FC65F54B85360C3CB0CAB2C7379A965CC841FB135B079495

 

Data String to generate hash :

String data = "^" + xTransId + "^" + xTestRequest + "^" + xResponseCode + "^"
+ xAuthCode + "^" + xCvv2RespCode + "^" + xCavvResponse + "^" + xAvsCode + "^"
+ xMethod + "^" + xAccountNumber + "^" + xAmount + "^" + xCompany + "^"
+ xFirstName + "^" + xLastName + "^" + xAddress + "^" + xCity + "^" + xState
+ "^" + xZip + "^" + xCountry + "^" + xPhone + "^" + xFax + "^" + xEmail + "^"
+ xShipToCompany + "^" + xShipToFirstName + "^" + xShipToLastName + "^"
+ xShipToAddress + "^" + xShipToCity + "^" + xShipToState + "^" + xShipToZip
+ "^" + xShipToCountry + "^" + xInvoiceNum + "^";

Hash generated:

F8FFE2918ABC5FCB3D01E878D5A22B51804BE2DCF97DD13D3971344AF7DE5D38F785B5374E396A502B8D8827E661E75B1DAFB359F50EE66B8234531B2A8A9C27

It is an issue with character encoding but we don't know how Auth.net handles the encoding before generating the hash which they send in the response.

Will really appreciate any help from the community to resolve this issue.

Thanks

Highlighted
Moderator
Posts: 102
Registered: ‎06-26-2018

Re: SHA-512 hash mismatch - Java

Hi vijayvanga

 

You should only use ISO 8859-1 characters. For more information on how to use the transHashSha2 value, please visit the Transaction Hash Upgrade Guide. 

 

I hope this is helpful to you. 

 

Regards,

Elaine

Highlighted
All Star
Posts: 725
Registered: ‎11-05-2018

Re: SHA-512 hash mismatch - Java

@vijayvanga

I have tested and working PHP code for this. The below post was modified but should work. You just need to adapt the code to java.

FYI SIM is on the chopping block this year and DPM is probably not too far behind.
Highlighted
All Star
Posts: 725
Registered: ‎11-05-2018
Highlighted
Member
Posts: 2
Registered: ‎04-13-2020

Re: SHA-512 hash mismatch - Java

I have converted the PHP code to Java, Still I am getting hash mismatch below is code which I have converted to java. Please can you help is there I am missing anything.




String allString = xTransId + "," + xTestRequest + "," + xResponseCode + "," + xAuthCode + "," + xCvv2RespCode + "," + xCavvResponse + "," + xAvsCode
+ "," + xMethod + "," + xAccountNumber + "," + xAmount + "," + xCompany + "," + xFirstName + "," + xLastName + "," + xAddress + "," + xCity + "," + xState
+ "," + xZip + "," + xCountry + "," + xPhone + "," + xFax + "," + xEmail + "," + xShipToCompany + "," + xShipToFirstName + "," + xShipToLastName
+ "," + xShipToAddress + "," + xShipToCity + "," + xShipToState + "," + xShipToZip
+ "," + xShipToCountry + "," + xInvoiceNum;

String[] splitString = allString.split(",");
LinkedList<String> linklist = new LinkedList<String>();
HashMap<String, String> map = convertSpecialCharcters();
for(String split : splitString)
{
String newSplit = URLEncoder.encode(split, "ISO-8859-1");
for (Map.Entry<String, String> entry : map.entrySet())
{
    newSplit = newSplit.replace(entry.getKey(), entry.getValue());
}
String[] explode = newSplit.split("%26");

String explodedValue = "";
for(String explodeValue : explode)
{
int i = explodeValue.indexOf("%3D");
if(i > 1)
explodeValue = explodeValue.substring(i);
explodeValue = explodeValue.replace("%3D", "");
explodeValue = explodeValue.replace("%2540", "@");
explodedValue = explodedValue + explodeValue;
}
linklist.add(explodedValue);
}
String data = "^";
for (String stringData : linklist)
{
data = data + stringData + "^";
}

String value = getHashedValue(data);

System.out.println("Hash ----- " + hash);
System.out.println("Value ---- " + value.toUpperCase());
System.out.println(hash.equalsIgnoreCase(value));


Thanks
Vijaykumar Vanga

Highlighted
All Star
Posts: 725
Registered: ‎11-05-2018

Re: SHA-512 hash mismatch - Java

@vijayvanga

To use my script you need to capture url encoded data. Raw post data in url encoded form.
Highlighted
New Member
Posts: 1
Registered: ‎06-23-2020

Re: SHA-512 hash mismatch - Java

I have tested and working PHP code for Official Website . The below post was modified but should work. You just need to adapt the code to java.