Validating the hmac
The HMAC is included in the parameters returned in the passback from QuickWeb, QuickConnect, QuickVault Web and QuickVault Connect. Use this to validate the parameters in the passback were not tampered.
- The parameters in the passback are signed using the
HMAC_SHA256
algorithm. - Your secure token request password is used as the secret in the
HMAC_SHA256
calculation. - Find the password by viewing your connection details in QuickStream.
To validate the hmac
parameter:
- Remove
hmac
from the list of parameters returned and order the parameters ASCIIbetically by name. - URL encode each parameter with
UTF-8
character encoding. - Join the parameter names and values with
=
and each pair with&
(as per a query string). - Generate the HMAC from this string using secure token request password.
- Hexadecimal encode the resulting string.
- Compare the HMAC string you generated to the
hmac
parameter in the passback.
HMAC validation example
This example illustrates a simple validation of the hmac
parameter in the passback.
Step 1: Get the list of parameters returned in the passback.
Parameter Name | Parameter Value |
---|---|
communityCode |
COMCODE |
supplierBusinessCode |
SUPP |
principalAmount |
10.00 |
customParam |
A custom parameter with special characters & . |
hmac |
dce3bc3945ca4d33151fb4c6a69971d86c35556cc2becafb3cb451f080af3d49 |
Step 2: Remove hmac
and order the parameters ASCIIbetically by name.
Parameter Name | Parameter Value |
---|---|
communityCode |
COMCODE |
customParam |
A custom parameter with special characters & . |
principalAmount |
10.00 |
supplierBusinessCode |
SUPP |
Step 3: URL encode each parameter with UTF-8 character encoding
Ensure the encoded characters are lowercase and not uppercase (for example, %3A
not %3a
.)
Parameter Name | Parameter Value |
---|---|
communityCode |
COMCODE |
customParam |
this+is+a+custom+param+with+special+characters+%26 |
principalAmount |
10.00 |
supplierBusinessCode |
SUPP |
Step 4: Join the parameter names and values with = and each pair with &.
communityCode=COMCODE&customParam=this+is+a+custom+param+with+special+characters+%26&principalAmount=10.00&supplierBusinessCode=SUPP
Step 5: Generate the HMAC from this string using secure token password.
Example hash function in Java
public static String hash( final String password, final String queryString )
{
final Mac mac = Mac.getInstance( "HmacSHA256" );
mac.init( new SecretKeySpec( password.getBytes( "UTF-8" ), "HmacSHA256" ) );
return Hex.encodeHexString( mac.doFinal( queryString.getBytes() ) );
}
Finally, compare the HMAC string you generated to the hmac
parameter in the passback. If the strings do not match, there has likely been tampering of the parameters and their values and should not be considered accurate.