title: Encoding a String in NetSuite SuiteScript 2.0
body: <p>I have to perform the following encoding on a string:</p>
  
  <ol>
  <li>Calculate SHA1 hash value, with output in hexadecimal format</li>
  <li>Apply a BASE64 encoding to the resulted hash</li>
  </ol>
  
  <p>I'm trying to do this in the code below, 'str' being the input and 'digest' the final encoded string.</p>
  
  <p>I've tried different ways without much success. The current code (below) throws an error:</p>
  
  <p><em>WrappedException: Wrapped java.lang.IllegalArgumentException: contains illegal character for hexBinary: crypto.SecretKey</em></p>
  
  <pre><code>var str = nonce + timestamp + secret;
  
  var secureString = HTTPS.createSecureString({
          input: str
      });
  
  secureString = secureString.hash({
          algorithm: CRYPTO.HashAlg.SHA1
      });
  
  var hexString = HTTPS.createSecretKey({
          encoding: HTTPS.Encoding.HEX,
          guid: secureString
      });
  
  var digest = ENCODE.convert({
          string: hexString,
          inputEncoding: ENCODE.Encoding.HEX,
          outputEncoding: ENCODE.Encoding.BASE_64
      });
  </code></pre>