title: How to encode 256bit AES key using base64?
body: <p>I am using NodeJS to interact with Amazon Web Services (specifically s3).  I am attempting to use <a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/ServerSideEncryptionCustomerKeys.html" rel="nofollow">Server side encryption with customer keys</a>.  Only AES256 is allowed as an encryption method.  The API specifies that the keys be base64 encoded.</p>
  
  <p>At the moment I am merely testing the AWS api, I am using throwaway test files, so security (and secure key generation) are not an issue at the moment.</p>
  
  <p>My problem is as follows: Given that I am in posession of a 256bit hexadecimal string, how do I obtain a base64 encoded string of the integer that that represents?</p>
  
  <p>My first instinct was to first parse the Hexadecimal string as an integer, and convert it to a string using <code>toString(radix)</code> specifying a radix of 64.  However <code>toString()</code> accepts a maximum radix of 36.  Is there another way of doing this?</p>
  
  <p>And even if I do this, is that a base64 encoded string of 256bit encryption key?  The API reference just says that it expects a key that is <a href="http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/frames.html" rel="nofollow">"appropriate for use with the algorithm specified"</a>. (I am using the putObject method).</p>