Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function rsaTest () {
/* You need to specify a name
* and a namespace for raw encryption key providers.
* The name and namespace that you use in the decryption keyring *must* be an exact,
* *case-sensitive* match for the name and namespace in the encryption keyring.
*/
const keyName = 'rsa-name'
const keyNamespace = 'rsa-namespace'
// Get your key pairs from wherever you store them.
const rsaKey = await generateRsaKeys()
/* The RSA keyring must be configured with the desired RSA keys
* If you only want to encrypt, only configure a public key.
* If you only want to decrypt, only configure a private key.
*/
const keyring = new RawRsaKeyringNode({ keyName, keyNamespace, rsaKey })
/* Encryption context is a *very* powerful tool for controlling and managing access.
* It is ***not*** secret!
* Encrypted data is opaque.
* You can use an encryption context to assert things about the encrypted data.
* Just because you can decrypt something does not mean it is what you expect.
* For example, if you are are only expecting data from 'us-west-2',
* the origin can identify a malicious actor.
* See: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
*/
const context = {
stage: 'demo',
purpose: 'simple demonstration app',
origin: 'us-west-2'
}
export function rsaKeyring (keyInfo: RsaKeyInfo, key: RSAKey) {
const keyName = key['key-id']
const keyNamespace = keyInfo['provider-id']
const rsaKey = key.type === 'private'
? { privateKey: key.material }
: { publicKey: key.material }
const padding = rsaPadding(keyInfo)
return new RawRsaKeyringNode({ keyName, keyNamespace, rsaKey, padding })
}