Generating license key using cocoafob in php

I'm using cocoafob library to generate license key but it's returning error while generating key.

Please check my below code and help me,

PHP

    public function make_license($product_code, $email)
    {

    $stringData = $product_code.",".$email;
    $binary_signature ="";
    openssl_sign($stringData, $binary_signature, $this->private_key, OPENSSL_ALGO_DSS1);
    // base 32 encode the signature
    $encoded = base32_encode($binary_signature);
    // replace O with 8 and I with 9
    $replacement = str_replace("O", "8", str_replace("I", "9", $encoded));
    //remove padding if any.
    $padding = trim(str_replace("=", "", $replacement));
    $dashed = rtrim(chunk_split($padding, 5,"-"));
    $theKey = substr($dashed, 0 , strlen($dashed) -1);
    }

    if ($_POST["pCode"] && $_POST["name"] && $_POST["email"])
    {
    include_once('license_generator.php');
    $lic = new License_Generator;
    $code = $lic->make_license($_POST["pCode"], $_POST["name"], $_POST["email"]);
    echo 'Your License:<br><strong>' . $code ."</strong>";
    }

1 answer

  • answered 2018-04-17 05:54 Indumathi

    You're getting internal server error in postman because the parameters are missed.You're posting 3 parameters but not passing those 3 to cocoafob library also you need to return the key after it generates.

    Please check the below code, Hope it will resolve your issue.

     public function make_license($product_code, $name, $email)
    {
    
    $stringData = $product_code.",".$name.",".$email;
    $binary_signature ="";
    openssl_sign($stringData, $binary_signature, $this->private_key, OPENSSL_ALGO_DSS1);
    // base 32 encode the signature
    $encoded = base32_encode($binary_signature);
    // replace O with 8 and I with 9
    $replacement = str_replace("O", "8", str_replace("I", "9", $encoded));
    //remove padding if any.
    $padding = trim(str_replace("=", "", $replacement));
    $dashed = rtrim(chunk_split($padding, 5,"-"));
    $theKey = substr($dashed, 0 , strlen($dashed) -1);
    
    return $theKey;
    }
    
    if ($_POST["pCode"] && $_POST["name"] && $_POST["email"])
    {
    include_once('license_generator.php');
    $lic = new License_Generator;
    $code = $lic->make_license($_POST["pCode"], $_POST["name"], $_POST["email"]);
    echo 'Your License:<br><strong>' . $code ."</strong>";
    }