title: Doing a SHA256withRSA with Google Apps Script
body: <p>I am trying to do a Google oAuth2 method in Google Apps Script by constructing the descripbed JWS/JWT stuff.</p>
  
  <p>Now, I can read a key file from Drive or maybe from another source, but how should I sign it with this file? Are there any methods or JavaSCript pieces to do this?</p>
  
  <pre><code>function Auth20(user) {
  var header = Utilities.base64Encode(JSON.stringify( {"alg":"RS256","typ":"JWT"} ) );
  var claimdata = {
  "iss":"1002979611916q0iraclc6q33xxxxxxxx@developer.gserviceaccount.com",
               "prn": user,
               "scope":"https://www.googleapis.com/auth/plus.circles.read",
               "aud":"https://accounts.google.com/o/oauth2/token",
                 "exp":new Date().getTime()/1000,
                 "iat":(new Date().getTime()/1000)+3600 
                }
  var claim = Utilities.base64Encode(JSON.stringify( claimdata ))
  
   var jws = header+"."+claim;
   var jwsbytes = [];
  
   for (var i = 0; i &lt; jws.length; ++i)
   {
   jwsbytes.push(jws.charCodeAt(i));
   }
    var key = DriveApp.getFileById("0B_5HSTQXtXmsU29fTE5xNWhvOVE").getBlob()
  </code></pre>