/** * @fn generate_key($username, $registration_date, $expiration_date, $license_type) * @short Singular license generator */ public static function generate_key($username, $registration_date = NULL, $expiration_date = NULL, $license_type = SingularLicense::SINGLE_USER_LICENSE) { $key = NULL; // Convert from ISO-8859-1 to UTF-8 $username = iconv("iso-8859-1", "utf-8", $username); // Calculate SHA-1 hash $hash = sha1($username); // License start date if (empty($registration_date)) { $registration_date = date("Y-m-d"); } // License expiration date if (empty($expiration_date)) { $expiration_date = date("Y-m-d", time() + SingularLicense::DEFAULT_LICENSE_DURATION); } // Digest to cypher $digest = "{$hash};{$registration_date};{$expiration_date};{$license_type}"; $priv_key_path = dirname(__FILE__) . "/../openssl/singular_private_key.pem"; if (file_exists($priv_key_path)) { $fp = fopen($priv_key_path, "r"); $priv_key = fread($fp, filesize($priv_key_path)); fclose($fp); // $passphrase is required if your key is encoded (suggested) $passphrase = ''; if (($res = openssl_get_privatekey($priv_key, $passphrase)) !== FALSE) { /* * NOTE: Here you use the returned resource value */ openssl_private_encrypt($digest, $crypttext, $res); // Calculate the key $key = Base64::encode_linelength($crypttext, 32); } } return $key; }