Skip to main content

Encrypt

Encrypts given plaintext with the specified key.

import { cloudApi, serviceClients, Session } from "@yandex-cloud/nodejs-sdk";

const SymmetricEncryptRequest =
cloudApi.kms.symmetric_crypto_service.SymmetricEncryptRequest;

(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.SymmetricCryptoServiceClient);

const result = await client.encrypt(
SymmetricEncryptRequest.fromPartial({
keyId: "keyId",
// versionId: "versionId",
// aadContext: Buffer.from([]),
plaintext: Buffer.from([]),
})
);
console.log(result);
})();

SymmetricEncryptRequest

keyId : string

ID of the symmetric KMS key to use for encryption.

versionId : string

ID of the key version to encrypt plaintext with. Defaults to the primary version if not specified.

aadContext : bytes

Additional authenticated data (AAD context), optional. If specified, this data will be required for decryption with the SymmetricDecryptRequest. Should be encoded with base64.

plaintext : bytes

Plaintext to be encrypted. Should be encoded with base64.

SymmetricEncryptResponse

keyId : string

ID of the symmetric KMS key that was used for encryption.

versionId : string

ID of the key version that was used for encryption.

ciphertext : bytes

Resulting ciphertext.