title: How to encrypt encrypt in ReactJS without AWS KMS accesskey and keyid
body: <p>I've been struggling a few days to find a proper solution for this
  Currently we need to encrypt some secrets in ReactJS and send to the backend API to decrypt using KMS asymmetric key, the encrypt/decrypt work fine by using the aws-sdk javascript version.</p>
  <p>The problem here is that to use this KMS.encyrpt provided by aws-sdk, requires providing AWS access key/secret which we don't want to expose in ReactJS, so I'm looking for 2 solutions here:</p>
  <ol>
  <li>To find a proper pure JavaScript library to encrypt the secrect using the public key downloaded from KMS service, but the problem is the algorithm RSAES_OAEP_SHA_256 is different, the problem described here: <a href="https://stackoverflow.com/questions/64255199/encryption-using-aws-kms-asymmetric-key">Encryption using AWS KMS Asymmetric key</a></li>
  <li>To use assumeRole to call the KMS to encrypt service rather than using a longer access key, but I cannot find a working example that can work with aws-sdk client so far</li>
  </ol>
  <p>I also found a similar question <a href="https://stackoverflow.com/questions/68880637/encrypt-with-jsencrypt-then-decrypt-with-aws-sdk-go">Encrypt with jsencrypt then decrypt with aws-sdk-go</a>, and that's the exact problem we don't want to expose the access key in the frontend</p>
  <p>I read through the aws client code and found it just a wrapper to call http request back to AWS service, so it doesn't really help to encrypt using a pure JavaScript library</p>
  <p>It'll be the best if aws-sdk client can encrypt directly using the downloadable public key but it doesn't seem to function in that way</p>
  <p>Any help or suggestion is appreciated, thanks in advance!</p>