I know I probably shouldn't be doing this in Perl but please humour me:
Trying to validate the signature of a PayPal REST API 2 Webhook. The 'raw_query' is the HTTP payload sent by PayPal which is CRC32 encoded as per PayPal. The Public Key Cert is hard-coded in for ease (this has been downloaded from PayPal and checked).
wh_id is the Webhook ID, from the PayPal Developer backend (when you add a webhook to your app).
Anyone any ideas why this always fails to verify?
#The X509 Public Key Cert provided by PayPal (redacted)
my $pp='-----BEGIN CERTIFICATE-----
.......
-----END CERTIFICATE-----';
#Create the original message that would have been signed by PayPal
my $msg=$ENV{'HTTP_PAYPAL_TRANSMISSION_ID'}.'|'.$ENV{'HTTP_PAYPAL_TRANSMISSION_TIME'}.'|'.$wh_id.'|'.crc32($ppn{'raw_query'});
#Get a Crypt::RSA object from the X509 Public Key provided by PayPal
my $x509 = Crypt::OpenSSL::X509->new_from_string($pp);
my $rsa = Crypt::OpenSSL::RSA->new_public_key($x509->pubkey());
$rsa->use_pkcs1_padding();
$rsa->use_sha256_hash();
#Base64-Decode the signature provided by PayPal
my $pp_sig = decode_base64($ENV{'HTTP_PAYPAL_TRANSMISSION_SIG'});
#Do the verification
if ($rsa->verify($msg,$pp_sig))){
}