Amazon Developer

as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases
Get Started
Design and Develop
Publish
Reference
Support
Skip to main content
The Vega Crypto API provides functionality that allows you to perform typical cryptographic operations such as read, generate, and manage cryptographic keys using industry-standard algorithms.
Note: Running this API in the simulator is not supported.

Get started

Setup

  1. Add the following library dependency to the dependencies section of your package.json file.

Usage

In the source file in which you are using the Vega Crypto functionality, import the data types that you need from the Turbo Module.
Instancing the Crypto class is always the first step to make use of the KeplerCrypto Turbo Module.
The following example code is for explanatory purposes and is simplified for clarity. Most of the methods in the Vega Crypto API throw an exception when an error occurs. Wrap your calls in a try-catch block to gracefully handle any errors that occur.
Check the documentation the specific exceptions that any particular method throws.

ECDSA signature and verification

The following example code includes ECDSA keypair generation, message signing, and verification.

Step 1: Create an ECDSA key builder

Step 2: Generate a keypair

You can generate an ECDSA keypair or construct a private key. To generate an ECDSA keypair, call buildGenerated().
To construct a private key from an existing DER string, call buildPrivateFromDer().
</viv>

Step 3: Create a signature context builder

Step 4: Sign the message and obtain the signature

Step 5: Verify the message with the signature

RSA signature and verification

The following example code includes RSA keypair generation, message signing, and verification.

Step 1: Create an RSA key builder

Step 2: Generate a keypair

You can generate an RSA keypair or construct a private key. To generate an RSA keypair, call buildGenerated().
To construct a private key from an existing DER string, call buildPrivateFromDer().

Step 3: Create a signature context builder and sign the message

Create a signature context builder by calling buildSigningContext() and then sign the message with the RSA-PKCS1 v1.5 scheme to get the signature.

Step 4: Verify the message

Use the signature to verify the message by calling rsaPkcs1Verifier.verify() which uses the RSA-PKCS1 v1.5 standard.

Step 5: Sign the message and get the signature

To sign the message using RSA-PSS standard call rsaPssSigner.sign() which returns the signature of the signed message.
To verify the message, call rsaPssVerifier.verify() and pass the signature of the message.

HMAC signature and verification

The following example shows how to generate a secret key, export the key, sign the data, and verify it.
Use an AES CBC Block Cipher to encrypt a message The following example shows how to generate an AES-256 key, export it, create an AES-256 CBC cipher context builder, and use it to sign a plaintext.

Use an AES CTR Block Cipher to encrypt a message

The following example shows how to generate an AES-CTR key, export it, create an AES-256 CTR cipher context builder, and use it to sign a plaintext.

Use an AES GCM Block Cipher to encrypt a message

The following example shows how to generate an AES-256 GCM key, export it, create an AES-256 GCM cipher context builder, and use it to sign a plaintext.

Use RSA-OAEP to encrypt a message

The following example shows how to generate an RSA-OAEP key, export it, create a context builder, and use it to sign a plaintext.

Create a message digest

The following code example calls getDigestAlgorithmByName() to get the digest, creates a digest context, encodes an example string, and gets a digest for the string.
Key derivation using HKDF (HMAC Key Derivation Function)

Key derivation using PBKDF2 (Password-Based Key Derivation Function 2)

Web Crypto API shim layer

The KeplerCrypto library provides a shim layer that implements the Web Crypto API. We refer to the existing Web Crypto API MDN documentation for the API methods and parameters.

Web Crypto usage example

The following example presents how to import and use the Web Crypto API shim layer.

Import the API

Initialize the WebCrypto object

Optional: Expose the crypto instance on globalThis

Call to Web Crypto APIs

The next code example generates an ECDH CryptoKeyPair.

Supported Web Crypto algorithms

This library is a work in progress and the Web Crypto implementation provides a subset of the whole W3C Web Crypto specification. More operations will be supported in future versions. Note: deriveKey is not supported in the Web Crypto shim layer implementation. For key derivation functionality, please use the standard Vega Crypto API, as shown in the above “Key derivation using HKDF” and “Key derivation using PBKDF2” examples.

Supported key formats for Web Crypto

When importing and exporting keys with the Web Crypto API, the following formats are supported: Format descriptions:
  • raw: Unformatted binary data, used for symmetric keys (AES or HMAC), or Elliptic Curve public keys.
  • pkcs8: PKCS #8 format for RSA or Elliptic Curve private keys.
  • spki: SubjectPublicKeyInfo format for RSA or Elliptic Curve public keys.
  • jwk: JSON Web Key format (supported by all key types)
Example of importing a key:

Web Crypto API Support Matrix

Algorithm Operations:
  • ✓ = Supported
  • ✗ = Not Supported

Overview of Vega Crypto

The Vega Crypto API provides functionality that allows you to perform typical cryptographic operations such as read, generate, and manage cryptographic keys using industry-standard algorithms.

Get started

The Vega Crypto API is supplied as part of the Kepler SDK.

Install and setup Vega Crypto

To add the API to your project, in the root directory of your app, open the package.json file and add the following dependency.

Use the Vega Crypto API in your app

In the source file in which you are using the Vega Crypto functionality, import the data types that you need from the Turbo Module.
Next, get a Crypto instance.
Instancing the Crypto class is always the first step to make use of the Vega Crypto Turbo Module.

Vega Crypto common use cases

The following example code is for explanatory purposes and is simplified for clarity. Most of the methods in the Vega Crypto API throw an exception when an error occurs. Wrap your calls in a try-catch block to gracefully handle any errors that occur. For example:
Check the documentation for any method that you call for the specific exceptions that it throws. Note: Running this Turbo Module in the simulator is not supported. ECDSA signature and verification The following example code includes ECDSA keypair generation, message signing, and verification.

Step 1: Create an ECDSA key builder

Step 2: Generate a keypair

You can generate an ECDSA keypair or construct a private key. To generate an ECDSA keypair, call buildGenerated().
To construct a private key from an existing DER string, call buildPrivateFromDer().

Step 3: Create a signature context builder

Step 4: Sign the message and obtain the signature

Step 5: Verify the message with the signature

RSA signature and verification The following example code includes RSA keypair generation, message signing, and verification.

Step 1: Create an RSA key builder

Step 2: Generate a keypair

You can generate an RSA keypair or construct a private key. To generate an RSA keypair, call buildGenerated().
To construct a private key from an existing DER string, call buildPrivateFromDer().

Step 3: Create a signature context builder and sign the message

Create a signature context builder by calling buildSigningContext() and then sign the message with the RSA-PKCS1 v1.5 scheme to get the signature.

Step 4: Verify the message

Use the signature to verify the message by calling rsaPkcs1Verifier.verify() which uses the RSA-PKCS1 v1.5 standard.

Step 5: Sign the message and get the signature

To sign the message using RSA-PSS standard call rsaPssSigner.sign() which returns the signature of the signed message.
To verify the message, call rsaPssVerifier.verify() and pass the signature of the message.
HMAC signature and verification The following example shows how to generate a secret key, export the key, sign the data and verify it.
Use an AES CBC Block Cipher to encrypt a message The following example shows how to generate an AES-256 key, export it, create an AES-256 CBC cipher context builder, and use it to encrypt a plaintext.
Use an AES CTR Block Cipher to encrypt a message The following example shows how to generate an AES-CTR key, export it, create an AES-256 CTR cipher context builder, and use it to encrypt a plaintext.
Use an AES GCM Block Cipher to encrypt a message The following example shows how to generate an AES-256 GCM key, export it, create an AES-256 GCM cipher context builder, and use it to encrypt a plaintext.
Use RSA-OAEP to encrypt a message The following example shows how to generate an RSA-OAEP key, export it, create a context builder, and use it to encrypt a plaintext.
Create a message digest The following code example calls getDigestAlgorithmByName() to get the digest, creates a digest context, encodes an example string, and gets a digest for the string.
Key derivation using HKDF (HMAC Key Derivation Function)
Key derivation using PBKDF2 (Password-Based Key Derivation Function 2)

Web Crypto API shim layer

The Vega Crypto library provides a shim layer that implements the Web Crypto API. We refer to the existing Web Crypto API MDN documentation for the API methods and parameters.

Web Crypto usage example

The following example presents how to import and use the Web Crypto API shim layer:

Import the API

Initialize the WebCrypto object

Optional: Expose the crypto instance on globalThis

Call to Web Crypto APIs

The next code example generates an ECDH CryptoKeyPair:

Supported Web Crypto algorithms

This library is a work in progress and the Web Crypto implementation provides a subset of the whole W3C Web Crypto specification. More operations will be supported in future versions.

Supported key formats for Web Crypto

When importing and exporting keys with the Web Crypto API, the following formats are supported: Format descriptions:
  • raw: Unformatted binary data, used for symmetric keys or Elliptic Curve public keys.
  • pkcs8: PKCS #8 format for RSA or Elliptic Curve private keys.
  • spki: SubjectPublicKeyInfo format for RSA or Elliptic Curve public keys.
  • jwk: JSON Web Key format for symmetric keys or RSA and Elliptic Curve public/private keys.
Example of importing a key:

Web Crypto API Support Matrix

Algorithm Operations:
  • ✓ = Supported
  • ✗ = Unsupported
  • — = Not applicable

Modules


Last modified on February 19, 2026