Encrypt
Encrypts given plaintext with the specified key.
- TypeScript
- Python
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);
})();
import os
import grpc
import yandexcloud
from yandex.cloud.kms.v1.symmetric_crypto_service_pb2_grpc import SymmetricCryptoServiceStub
from yandex.cloud.kms.v1.symmetric_crypto_service_pb2 import SymmetricEncryptRequest
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(SymmetricCryptoServiceStub)
response = service.Encrypt(
SymmetricEncryptRequest(
key_id="keyId",
# version_id = "versionId",
# aad_context = b'',
plaintext=b"",
)
)
print(response)
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.