title: ASP.NET [Facebook API] - Reading a signed_request (only given in docs as PHP)
body: <p>Hey guys, just trying to decode my signed request.. I've done a bit of searching and haven't found a VB alternative..</p>
  
  <p>The signed_request parameter is a concatenation of a HMAC SHA-256 signature string, a period (.) and a base64url encoded JSON object.</p>
  
  <p>signed_request:</p>
  
  <pre><code>vlXgu64BQGFSQrY0ZcJBZASMvYvTHu9GQ0YM9rjPSso
  .
  eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsIjAiOiJwYXlsb2FkIn0
  </code></pre>
  
  <p>PHP function to decode request:</p>
  
  <pre><code>&lt;?php
  define('FACEBOOK_APP_ID', 'your_app_id');
  define('FACEBOOK_SECRET', 'your_app_secret');
  
  function parse_signed_request($signed_request, $secret) {
    list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
  
    // decode the data
    $sig = base64_url_decode($encoded_sig);
    $data = json_decode(base64_url_decode($payload), true);
  
    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
      error_log('Unknown algorithm. Expected HMAC-SHA256');
      return null;
    }
  
    // check sig
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
    if ($sig !== $expected_sig) {
      error_log('Bad Signed JSON signature!');
      return null;
    }
  
    return $data;
  }
  
  function base64_url_decode($input) {
      return base64_decode(strtr($input, '-_', '+/'));
  }
  
  if ($_REQUEST) {
    echo '&lt;p&gt;signed_request contents:&lt;/p&gt;';
    $response = parse_signed_request($_REQUEST['signed_request'], 
                                     FACEBOOK_SECRET);
    echo '&lt;pre&gt;';
    print_r($response);
    echo '&lt;/pre&gt;';
  } else {
    echo '$_REQUEST is empty';
  }
  ?&gt;
  </code></pre>
  
  <p>And the result is the decoded JSON object:</p>
  
  <pre><code>    {
     "oauth_token": "...big long string...",
     "algorithm": "HMAC-SHA256",
     "expires": 1291840400,
     "issued_at": 1291836800,
     "registration": {
        "name": "Paul Tarjan",
        "email": "fb@paulisageek.com",
        "location": {
           "name": "San Francisco, California",
           "id": 114952118516947
        },
        "gender": "male",
        "birthday": "12/16/1985",
        "like": true,
        "phone": "555-123-4567",
        "anniversary": "2/14/1998",
        "captain": "K",
        "force": "jedi",
        "live": {
           "name": "Denver, Colorado",
           "id": 115590505119035
        }
     },
     "registration_metadata": {
        "fields": "[\n {'name':'name'},\n {'name':'email'},\n {'name':'location'},\n {'name':'gender'},\n {'name':'birthday'},\n {'name':'password',   'view':'not_prefilled'},\n {'name':'like',       'description':'Do you like this plugin?', 'type':'checkbox',  'default':'checked'},\n {'name':'phone',      'description':'Phone Number',             'type':'text'},\n {'name':'anniversary','description':'Anniversary',              'type':'date'},\n {'name':'captain',    'description':'Best Captain',             'type':'select',    'options':{'P':'Jean-Luc Picard','K':'James T. Kirk'}},\n {'name':'force',      'description':'Which side?',              'type':'select',    'options':{'jedi':'Jedi','sith':'Sith'}, 'default':'sith'},\n {'name':'live',       'description':'Best Place to Live',       'type':'typeahead', 'categories':['city','country','state_province']},\n {'name':'captcha'}\n]"
     },
     "user_id": "218471"
  }
  </code></pre>
  
  <p>So does anyone see how to get from point A (php) to point B (VB version)?</p>
  
  <p>Thanks in advance</p>