How to use the @aws-sdk/util-base64-browser.toBase64 function in @aws-sdk/util-base64-browser

To help you get started, we’ve selected a few @aws-sdk/util-base64-browser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-encryption-sdk-javascript / modules / example-browser / src / multi_keyring.ts View on Github external
/* Find data to encrypt. */
  const plainText = new Uint8Array([1, 2, 3, 4, 5])

  /* Encrypt the data. */
  const { result } = await encrypt(keyring, plainText, { encryptionContext: context })

  /* Log the plain text
   * only for testing and to show that it works.
   */
  console.log('plainText:', plainText)
  document.write('<br>plainText:' + plainText + '<br>')

  /* Log the base64-encoded result
   * so that you can try decrypting it with another AWS Encryption SDK implementation.
   */
  const resultBase64 = toBase64(result)
  console.log(resultBase64)
  document.write(resultBase64)

  /* Decrypt the data.
   * This decrypt call could be done with **any** of the 3 keyrings.
   * Here we use the multi-keyring, but
   * decrypt(kmsKeyring, result)
   * decrypt(aesKeyring, result)
   * would both work as well.
   */
  const { plaintext, messageHeader } = await decrypt(keyring, result)

  /* Grab the encryption context so you can verify it. */
  const { encryptionContext } = messageHeader

  /* Verify the encryption context.
github aws / aws-encryption-sdk-javascript / modules / example-browser / src / kms_simple.ts View on Github external
/* Find data to encrypt. */
  const plainText = new Uint8Array([1, 2, 3, 4, 5])

  /* Encrypt the data. */
  const { result } = await encrypt(keyring, plainText, { encryptionContext: context })

  /* Log the plain text
   * only for testing and to show that it works.
   */
  console.log('plainText:', plainText)
  document.write('<br>plainText:' + plainText + '<br>')

  /* Log the base64-encoded result
   * so that you can try decrypting it with another AWS Encryption SDK implementation.
   */
  const resultBase64 = toBase64(result)
  console.log(resultBase64)
  document.write(resultBase64)

  const { plaintext, messageHeader } = await decrypt(keyring, result)

  /* Grab the encryption context so you can verify it. */
  const { encryptionContext } = messageHeader

  /* Verify the encryption context.
   * If you use an algorithm suite with signing,
   * the Encryption SDK adds a name-value pair to the encryption context that contains the public key.
   * Because the encryption context might contain additional key-value pairs,
   * do not add a test that requires that all key-value pairs match.
   * Instead, verify that the key-value pairs you expect match.
   */
  Object
github aws / aws-encryption-sdk-javascript / modules / example-browser / src / aes_simple.ts View on Github external
/* Find data to encrypt. */
  const plainText = new Uint8Array([1, 2, 3, 4, 5])

  /* Encrypt the data. */
  const { result } = await encrypt(keyring, plainText, { encryptionContext: context })

  /* Log the plain text
   * only for testing and to show that it works.
   */
  console.log('plainText:', plainText)
  document.write('<br>plainText:' + plainText + '<br>')

  /* Log the base64-encoded result
   * so that you can try decrypting it with another AWS Encryption SDK implementation.
   */
  const resultBase64 = toBase64(result)
  console.log(resultBase64)
  document.write(resultBase64)

  const { plaintext, messageHeader } = await decrypt(keyring, result)

  /* Grab the encryption context so you can verify it. */
  const { encryptionContext } = messageHeader

  /* Verify the encryption context.
   * If you use an algorithm suite with signing,
   * the Encryption SDK adds a name-value pair to the encryption context that contains the public key.
   * Because the encryption context might contain additional key-value pairs,
   * do not add a test that requires that all key-value pairs match.
   * Instead, verify that the key-value pairs you expect match.
   */
  Object
github aws / aws-encryption-sdk-javascript / modules / example-browser / src / rsa_simple.ts View on Github external
/* Find data to encrypt. */
  const plainText = new Uint8Array([1, 2, 3, 4, 5])

  /* Encrypt the data. */
  const { result } = await encrypt(keyring, plainText, { encryptionContext: context })

  /* Log the plain text
   * only for testing and to show that it works.
   */
  console.log('plainText:', plainText)
  document.write('<br>plainText:' + plainText + '<br>')

  /* Log the base64-encoded result
   * so that you can try decrypting it with another AWS Encryption SDK implementation.
   */
  const resultBase64 = toBase64(result)
  console.log(resultBase64)
  document.write(resultBase64)

  const { plaintext, messageHeader } = await decrypt(keyring, result)

  /* Grab the encryption context so you can verify it. */
  const { encryptionContext } = messageHeader

  /* Verify the encryption context.
   * If you use an algorithm suite with signing,
   * the Encryption SDK adds a name-value pair to the encryption context that contains the public key.
   * Because the encryption context might contain additional key-value pairs,
   * do not add a test that requires that all key-value pairs match.
   * Instead, verify that the key-value pairs you expect match.
   */
  Object
github aws / aws-encryption-sdk-javascript / modules / material-management-browser / src / bytes2_jwk.ts View on Github external
export function bytes2JWK (rawKeyBytes: Uint8Array): JsonWebKey {
  // See https://tools.ietf.org/html/rfc7515#appendix-C Base64url Encoding
  const base64 = toBase64(rawKeyBytes)
  const base64Url = base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '')
  return {
    kty: 'oct',
    k: base64Url
  }
}
github aws / aws-encryption-sdk-javascript / modules / material-management-browser / src / browser_cryptographic_materials_manager.ts View on Github external
const backend = await getWebCryptoBackend()
    const subtle = getNonZeroByteBackend(backend)

    const webCryptoAlgorithm = { name: 'ECDSA', namedCurve }
    const extractable = false
    const usages = ['sign']
    const format = 'raw'

    const { publicKey, privateKey } = await subtle.generateKey(webCryptoAlgorithm, extractable, usages)
    const publicKeyBytes = await subtle.exportKey(format, publicKey)
    const compressPoint = SignatureKey.encodeCompressPoint(new Uint8Array(publicKeyBytes), suite)
    const signatureKey = new SignatureKey(privateKey, compressPoint, suite)
    return new WebCryptoEncryptionMaterial(
      suite,
      { ...encryptionContext, [ENCODED_SIGNER_KEY]: toBase64(compressPoint) }
    )
      .setSignatureKey(signatureKey)
  }
github aws / aws-sdk-js-v3 / packages / util-base64-universal / src / index.ts View on Github external
export function toBase64(input: Uint8Array): string {
  if (isNode()) {
    return nodeToBase64(input);
  }

  return browserToBase64(input);
}

@aws-sdk/util-base64-browser

A pure JS Base64 <-> UInt8Array converter

Apache-2.0
Latest version published 1 year ago

Package Health Score

72 / 100
Full package analysis

Similar packages