make_license('GESTOBM30', 'Sandro Noel', 'sandro.noel@gesosoft.com'); // to verify a Key from cocoafob place it in here. echo "

Verify the cocoafob License
"; ?>
verify_license('GESTOBM30', 'Sandro Noel', 'sandro.noel@gesosoft.com',$key); } ?> private_key = file_get_contents('./dsa_priv.pem', FILE_USE_INCLUDE_PATH); //read the public Key from disk $this->public_key = file_get_contents('./dsa_pub.pem', FILE_USE_INCLUDE_PATH); }#-#constructor() #-############################################# # desc: Create a license public function make_license($product_code, $name, $email) { // Generae a sha1 digest with the passed parameters. $stringData = $product_code.",".$name.",".$email; echo "Data: ".$stringData."
"; $binary_signature =""; openssl_sign($stringData, $binary_signature, $this->private_key, OPENSSL_ALGO_DSS1); echo "Binary Sig: ".$binary_signature."
"; // base 32 encode the stuff $encoded = base32_encode($binary_signature); echo "Original Key: ". $encoded ."
"; echo "Key Length: ". strlen($encoded) ."
"; // replace O with 8 and I with 9 $replacement = str_replace("O", "8", str_replace("I", "9", $encoded)); echo "Replaced: " .$replacement . "
"; //remove padding if any. $padding = trim(str_replace("=", "", $replacement)); echo "Stripped: " .$padding . "
"; $dashed = rtrim(chunk_split($padding, 5,"-")); $theKey = substr($dashed, 0 , strlen($dashed) -1); echo "Dashed: " .$theKey . "

"; echo "Verify the just created License
"; $this->verify_license($product_code, $name, $email, $theKey); return $theKey; } #-############################################# # desc: Verify License public function verify_license($product_code, $name, $email, $lic) { echo "Original: " .$lic . "
"; // replace O with 8 and I with 9 $replacement = str_replace("8", "O", str_replace("9", "I", $lic)); echo "Replaced: " .$replacement . "
"; //remove Dashes. $undashed = trim(str_replace("-", "", $replacement)); echo "Undashed: " .$undashed . "
"; echo "Key Length: ". strlen($undashed) ."
"; // Pad the output length to a multiple of 8 with '=' characters $desiredLength = strlen($undashed); if($desiredLength % 8 != 0) { $desiredLength += (8 - ($desiredLength % 8)); $undashed = str_pad($undashed, $desiredLength, "="); } echo "padded: " .$undashed . "
"; // decode Key $decodedHash = base32_decode($undashed); echo "Binary Sig: ".$decodedHash. "
"; //digest the original Data $stringData = $product_code.",".$name.",".$email; $ok = openssl_verify($stringData, $decodedHash, $this->public_key, OPENSSL_ALGO_DSS1); if ($ok == 1) { echo "GOOD"; } elseif ($ok == 0) { echo "BAD"; } else { echo "ugly, error checking signature"; } } } # Class License ?>