Hello, We hold very good work experience in PHP DEVEOPMENT AND DESIGNING . Kindly contact us if you are looking to get anything built. Email:
Hi, I have about 50 lines of a file which i need converted, i am willing to pay for this too, Half of it has already been converted but my programmer is a php specialist and isn't too sure about it, so i need someone to convert the rest and verify the half that my programmer converted is correct, its a quick job and i will pay too. There are 5 functions that need to be converted. The original .net file is below and my programmers attempt at converted it is below that, please take a look at provide a price for this. .NET FILE: To create the encryption variable, use the following algorithm: //compute a signature as the url compatible base64 encoded hmac-sha1. //input the complete absolute url sans &s=, something like // -- CoNVERT THE FUNCTIONS BELOW TO PHP -- public class UrlSigner { private readonly HMAC hmac; private readonly string signatureParam; public UrlSigner(string secret) : this(secret, "x") {} private UrlSigner(string secret, string name) { this.hmac = new HMACSHA1(GetBytes(secret)); this.signatureParam = string.Format("{0}=", name); } public string Sign(string url) { var urlToSign = UrlToSign(url); var bytes = GetBytes(urlToSign); var signature = hmac.ComputeHash(bytes, 0, bytes.Length); return string.Format("{0}{1}{2}", urlToSign, signatureParam, Base64ForUrl(signature)); } public bool Verify(string url) { var npos = url.LastIndexOf(signatureParam); if(npos == -1) return false; return Sign(url.Substring(0, npos)) == url; } string UrlToSign(string url) { if(!url.Contains('?')) return url + '?'; if(url.EndsWith("?") || url.EndsWith("&")) return url; return url + "&"; } byte[] GetBytes(string s){ return Encoding.UTF8.GetBytes(s); } string Base64ForUrl(byte[] bytes) { return Convert.ToBase64String(bytes) .Replace('+', '-') .Replace('/', '_') .Replace("=", string.Empty); } } Code (markup): .PHP Partially converted File: <?php class Federated { public static $signatureParam = null; /* This is the constructor function i figured it must run before anything else public UrlSigner(string secret) : this(secret, "x") {} private UrlSigner(string secret, string name) { this.hmac = new HMACSHA1(GetBytes(secret)); this.signatureParam = string.Format("{0}=", name); } */ public static function init($secret,$name) { //this.hmac = new HMACSHA1(GetBytes(secret)); i donno about this line, does we have anything equalient in php? self::$signatureParam = $name.'='; // not sure about this one either } // Sign //public string Sign(string url) //{ // var urlToSign = UrlToSign(url); // var bytes = GetBytes(urlToSign); // var signature = hmac.ComputeHash(bytes, 0, bytes.Length); // return string.Format("{0}{1}{2}", urlToSign, signatureParam, Base64ForUrl(signature)); //} public static function sign($url) { $urlToSign = self::url_to_sign($url); $bytes = self::get_bytes($urlToSign); $signature = sha1($bytes); // i dont think this is right, the "secret" must be in it somehow, maybe "$bytes . $secret" ? i really dont know return $urlToSign.self::$signatureParam.self::base64_for_url($signature); // not sure if this is right either. } // Verify // public bool Verify(string url) // { // var npos = url.LastIndexOf(signatureParam); // // if(npos == -1) // return false; // // return Sign(url.Substring(0, npos)) == url; // } public static function verify($url) { $npos = lastIndexOf(self::$signatureParam); if($npos == -1) { return false; } return // i dont really get this one tbh } // Prepare url for parameters, URL must end with ? or & // string UrlToSign(string url) // { // if(!url.Contains('?')) // return url + '?'; // // if(url.EndsWith("?") || url.EndsWith("&")) // return url; // // return url + "&"; // } public static function url_to_sign($url) { if(strpos($url,'?')===false) { return $url . '?'; } if(substr($url, -1) == '?' OR substr($url, -1) == '&') { return $url; } return $url . '&'; } // donno about this one, it looks like this is what its doing but what the hell do i know? // byte[] GetBytes(string s){ return Encoding.UTF8.GetBytes(s); } public static function get_bytes($str) { return utf8_encode($str) } // Prepare string for use in URL (a little unsure about the replacement of = sign though, but seems like this is it) // string Base64ForUrl(byte[] bytes) // { // return Convert.ToBase64String(bytes).Replace('+', '-').Replace('/', '_').Replace("=", string.Empty); // } public static function base64_for_url($string) { $string = base64_encode($string); // replace + with - $string = str_replace('+'.'-',$string); // replace / with _ $string = str_replace('/'.'_',$string); // replace = with nothing $string = str_replace('='.'',$string); // Return an URL compatible string: return $string; } } // php don't have lastIndexOf function so made one: function lastIndexOf($string,$item) { $index=strpos(strrev($string),strrev($item)); if ($index){ $index=strlen($string)-strlen($item)-$index; return $index; } else return -1; } ?> Code (markup): Any Help with this is appreciated. Thank you