question

exelanzgirija avatar image
exelanzgirija asked exelanzgirija published

PHP: Getting "Please provide either raw pan or encrypted pan" during Card Token generation

Below is my php code for Encrypt card data:

<?php

ini_set('display_errors', 1);

ini_set('display_startup_errors', 1);

error_reporting(E_ALL);


//Code not working for line 7 and 8

//include('phpseclib3/Crypt/RSA.php');

//include('phpseclib3/Math/BigInteger.php');


include 'vendor/autoload.php';

use phpseclib3\Crypt\PublicKeyLoader;

use phpseclib3\Crypt\RSA;

use phpseclib3\Math\BigInteger;

use phpseclib3\Net\SSH2;


//card number

$card_number = "4242424242424242";


//Get Public Encryption Key from CDN ...

$PUBLIC_ENCRYPTION_KEYS_URL = "https://checkout.clover.com/assets/keys.json";

$TA_PUBLIC_KEYS_JSON_ARRAY = file_get_contents($PUBLIC_ENCRYPTION_KEYS_URL);

$TA_PUBLIC_KEYS = json_decode($TA_PUBLIC_KEYS_JSON_ARRAY,true);


//Parse the Base64 public key string (returned by the CDN). Obtain the modulus and exponent.

$pa_key = bin2hex( base64_decode( $TA_PUBLIC_KEYS['TA_PUBLIC_KEY_DEV'] ) );

$modulus = substr( $pa_key, 0, 512 );

$exponent = substr( $pa_key, -5 );


//Generate an RSA public key using the modulus and exponent values.

$rsa_public_key = PublicKeyLoader::load(

array(

'e' => new BigInteger( $exponent, 16 ),

'n' => new BigInteger( $modulus, 16 ),

)

);

//print_r($rsa_public_key); exit;

//Prepend the prefix value to the card number.

//Using the public key, encrypt the combined prefix and card number.

openssl_public_encrypt( '00000000'.$card_number, $encrypted, $rsa_public_key, OPENSSL_PKCS1_OAEP_PADDING );

$pan = base64_encode( $encrypted );

print_r($pan);

?>

It is generating an encrypted pan code. While using this code for encryption the "Please provide either raw pan or encrypted pan" error is coming. What am i doing wrong?

access token
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community