Our authorize.net processing is done in some OLD perl cgi code - any perl programmers out there?
We are trying to convert to the SHA-512 hashing. Our current processing uses MD5, via the perl module Digest::MD5.
I use LWP::UserAgent to POST directly to the secure.authorize.net gateway transact dll URL.
What I get returned is an array of values. The MD5 hash is currently in the 38th array element. Authorize.net has been unable to tell me where I can find the returned SHA-512 hash value to compare to what I am generating in the program.
For my test:
I changed it to use Digest::SHA for the hashing. I generated the signature key and have it stored in hex in our database.
my $sha512_string = '^' . $auth_net_login_id . '^' . $tranid . '^' . $grandtotal . '^';
my $key = pack 'H*', $sig_key; ##to convert the store hex value to binary - as recommended here
my $sha512 = Digest::SHA->new;
my $sent_sha512_hash = $sha512->hmac_sha512($sha512_string, $key);
When I display that value, it just shows a bunch of weird characters on the screen - I don't know if that's expected or not. I am only displaying it to compare to what comes from authorize.net.
When the values are returned from Authorize.net (in the array), I display all the elements. There is a value in element 68 that looks like a hex value but that isn't what is in the hash that I generated.
So, isn't the hash returned from Authorize.net in the array? If not, then how do I obtain it using the methods we currently have in place? I don't consider this as using the API. Or is the problem that I am hashing it wrong on my end?
I obtained the perl code for our current processing via Authorize.net MANY years ago from one of their perl customers. It has worked fine ever since. I do not have the knowledge, experience or brain power to change the whole process, unless someone could provide all the perl code (I know that's asking a lot). I also have a general knowlege of php but unfortunately the examples on this forum are too different from our perl process to be able to correlate the two.
I hope someone can help! Thanks in advance!
Solved! Go to Solution.
โ01-16-2019 11:07 AM
I don't want to discourage you form implementing a security feature you think is needed. However, take a look a https://support.authorize.net/s/article/What-is-the-MD5-Hash-Security-feature-and-how-does-it-work - even authorize.net doesn't think it's needed for AIM
If you are indeed using AIM, you may be spending a lot of time on something not really needed, you could probably just comment out the part of your code that validates the hash.
If you are using AIM the path forward, as others have said, is to move to a more up to date API. Althought this is perhaps not the forum to say it, there are other companies with secure APIs that are much easier to use, and offer better support. 70 plus posts, mostly of people exchanging their ignorance, and not a single post from authorize.net says it all.
โ01-23-2019 05:40 PM
โ01-16-2019 06:12 PM
@smorrow123 The bunch of weird characters in the key are expected, you've taken a string of hex characters (ex. A4F1...etc) and packed their binary values in a variable. When perl tries to inerpret these as a string it results in "random" characters.
The solution to your problem is probably needing $sha512_string to be the 30 value thing described here:
I used the CGI perl module which allows parameters to be accessed in a named format (like 'x_SHA2_Hash') this might be very difficult to figure out which parameter is which if all you have is an array of values. Using CGI my solution is:
my $QUERY = new CGI; # This would be definied somewhere else my $x_SHA2_hash = $QUERY->param('x_SHA2_Hash'); my @keys = ( 'x_trans_id', 'x_test_request', 'x_response_code', 'x_auth_code', 'x_cvv2_resp_code', 'x_cavv_response', 'x_avs_code', 'x_method', 'x_account_number', 'x_amount', 'x_company', 'x_first_name', 'x_last_name', 'x_address', 'x_city', 'x_state', 'x_zip', 'x_country', 'x_phone', 'x_fax', 'x_email', 'x_ship_to_company', 'x_ship_to_first_name', 'x_ship_to_last_name', 'x_ship_to_address', 'x_ship_to_city', 'x_ship_to_state', 'x_ship_to_zip', 'x_ship_to_country', 'x_invoice_num' ); my $key; my $plain_text = "^"; foreach $key ( @keys ) { $plain_text .= $QUERY->param($key)."^"; } $key = pack 'H*', $signature_key; $hash_val = hmac_sha512_hex( $plain_text, $key ); if ( defined($x_SHA2_hash) && $x_SHA2_hash ne '' && lc($hash_val) eq lc($x_SHA2_hash) ) { $authorized = 1; }
โ01-17-2019 03:17 AM
Renaissance -
After my first post, I changed the hashing to hex (they donโt tell you that, but the old MD5 hash was done in hex, so I thought this one might be, too), and then had a result which looked more like what I needed it to be. But it still didnโt match what was in the 68th element of the returned array. The way you suggested is exactly what I did in my test. I displayed all the values individually for each array element returned. And that 68th element is the one that looked like it might be a hex hash value. Like I said, Authorize.net canโt tell me how the hashed value is returned or how I access it. So, all I have to go by is visual confirmation. And whatโs in the 68th element doesnโt match what is in my hex-hashed value.
I use the LWP perl module to access the AuthorizeNet URL directly. I donโt know what DPM is. You said you โposted some code that may workโ. Where is that? Iโm a newbie on the forum.
Thanks!
โ01-17-2019 04:34 AM - edited โ01-17-2019 04:38 AM
Tmnejp-
I changed my hashing to hex, and that value made a lot more sense, so thatโs what Iโm working with now.
I donโt understand why Authorize.net specifically said to hash the 3 items along with the sig-key, but youโre saying we need to go with 30 of them. Iโm not using SIM - are you? And if not, are you still using this method successfully?
Iโm willing to try anything, but now I need to understand what 30 items youโre using. The post you linked to said 30 fields, but the example only had 15. Exactly what fields are those? Are they what you prepared to send TO authorize.net OR are they what authorize.net returned after authorization? It looks like what authorize.net returned but I have more than 30 elements in the returned array! There are some that I specifically use, so I know where they are, but to match what you have here, Iโd have to get the other ones defined. I no longer have any documentation for this.
This has me SO aggravated!! Why canโt authorize.net tell us the correct information??
I wonโt be able to work on this for a few days - but Iโll monitor responses and give it a try when I can.
Thanks for your help!
โ01-17-2019 04:57 AM
โ01-17-2019 09:21 AM
โ01-17-2019 09:27 AM
@Renaissance Is there a way to get a copy of the SIM/DPM documentation? Does it include information for SHA-512? The old MD5 method only uses 3 fields along with the MD5 hash, and the Authorize.net rep I talked to said it would be very similar to the MD5 implementation.
Wonโt be working on this again until next week, but Iโd like to get my ducks in a row in the meantime. Thx.
โ01-18-2019 07:54 AM
โ01-18-2019 09:23 AM
Hey,
I use LWP too using Perl and MySQL. You are using DPM which uses the POST METHOD.
An also stuck, nothing worked. I used MySQL SHA2 Function and the HEX AND UNHEX function
to no avail. I have over 100+ counties and municipalities and these governments account resist changes the same way they resist a plague.
Am willing to pay anyone who can help with the code.
Thx
โ01-20-2019 07:25 PM