Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const _wrapKey = async (material: NodeEncryptionMaterial) => {
/* Precondition: Public key must be defined to support encrypt. */
if (!publicKey) throw new Error('No public key defined in constructor. Encrypt disabled.')
const { buffer, byteOffset, byteLength } = unwrapDataKey(material.getUnencryptedDataKey())
const encryptedDataKey = publicEncrypt(
{ key: publicKey, padding },
Buffer.from(buffer, byteOffset, byteLength))
const providerInfo = this.keyName
const providerId = this.keyNamespace
const flag = KeyringTraceFlag.WRAPPING_KEY_ENCRYPTED_DATA_KEY
const edk = new EncryptedDataKey({ encryptedDataKey, providerInfo, providerId })
return material.addEncryptedDataKey(edk, flag)
}