function verify_license($product_code, $name, $copies, $license) { $signature = array(); $license = str_replace('9', 'I', $license); $license = str_replace('8', 'O', $license); $license = str_replace('-', '', $license); $compositeLicenseCode = make_license_source($product_code, $name); // pad out the license key $padded_length = strlen($license) % 8; if ($padded_length == 0) { $padded_length = strlen($license); } else { $padded_length = (intval(strlen($license) / 8) + 1) * 8; } $padded = $license . str_repeat('=', $padded_length - strlen($license)); $signature = base32_decode($padded, base32_decode_buffer_size(strlen($padded))); $key = file_get_contents("./lib/dsapub512.pem"); $pukeyid = openssl_get_publickey($key); $valid = openssl_verify($compositeLicenseCode, $signature, $pukeyid, OPENSSL_ALGO_DSS1); return $valid == 1; }
$output[$bytes + 1] = $currentByte << 7; if ($input[$offset + 5] == '=') { // print "Return + 5 bytes:$bytes\n"; return arrayToString($output, $bytes + 1); } else { $bytes++; } $output[$bytes] += decode_bits($input[$offset + 5]) << 2; $currentByte = decode_bits($input[$offset + 6]); $output[$bytes] += $currentByte >> 3; $output[$bytes + 1] = ($currentByte & 0x7) << 5; if ($input[$offset + 7] == '=') { // print "Return + 7 bytes:$bytes\n"; return arrayToString($output, $bytes + 1); } else { $bytes++; } $output[$bytes] += decode_bits($input[$offset + 7]) & 0x1f; $bytes++; } return arrayToString($output, $bytes); } $test = false; if ($test) { print "buff len " . base32_decode_buffer_size(8) . "\n"; print "buff len " . base32_decode_buffer_size(80) . "\n"; $x = base32_decode('GEZDGNBV', base32_decode_buffer_size(8)); $y = base32_decode('MFRGGZDF', base32_decode_buffer_size(8)); echo "{$x} should be 12345\n"; echo "{$y} should be abcde\n "; }