Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@google-cloud/kms

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/kms

Google Cloud Key Management Service (KMS) API client for Node.js

  • 2.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
68K
decreased by-46.29%
Maintainers
1
Weekly downloads
 
Created

What is @google-cloud/kms?

@google-cloud/kms is a Node.js client library for Google Cloud Key Management Service (KMS). It allows you to manage cryptographic keys for your cloud services the same way you do on-premises. You can create, use, rotate, and destroy cryptographic keys, and it supports both symmetric and asymmetric keys.

What are @google-cloud/kms's main functionalities?

Create a Key Ring

This code sample demonstrates how to create a new key ring in Google Cloud KMS. A key ring is a grouping of keys that allows you to manage them together.

const { KeyManagementServiceClient } = require('@google-cloud/kms');
const client = new KeyManagementServiceClient();

async function createKeyRing() {
  const locationId = 'global';
  const keyRingId = 'my-key-ring';
  const parent = client.locationPath('my-project', locationId);

  const [keyRing] = await client.createKeyRing({
    parent: parent,
    keyRingId: keyRingId,
    keyRing: {}
  });

  console.log(`Created key ring: ${keyRing.name}`);
}

createKeyRing();

Create a Crypto Key

This code sample demonstrates how to create a new cryptographic key within a key ring. The key can be used for encryption and decryption.

const { KeyManagementServiceClient } = require('@google-cloud/kms');
const client = new KeyManagementServiceClient();

async function createCryptoKey() {
  const locationId = 'global';
  const keyRingId = 'my-key-ring';
  const cryptoKeyId = 'my-crypto-key';
  const parent = client.keyRingPath('my-project', locationId, keyRingId);

  const [cryptoKey] = await client.createCryptoKey({
    parent: parent,
    cryptoKeyId: cryptoKeyId,
    cryptoKey: {
      purpose: 'ENCRYPT_DECRYPT',
      versionTemplate: {
        algorithm: 'GOOGLE_SYMMETRIC_ENCRYPTION'
      }
    }
  });

  console.log(`Created crypto key: ${cryptoKey.name}`);
}

createCryptoKey();

Encrypt Data

This code sample demonstrates how to encrypt data using a cryptographic key. The plaintext data is encrypted and the ciphertext is returned.

const { KeyManagementServiceClient } = require('@google-cloud/kms');
const client = new KeyManagementServiceClient();

async function encryptData() {
  const locationId = 'global';
  const keyRingId = 'my-key-ring';
  const cryptoKeyId = 'my-crypto-key';
  const name = client.cryptoKeyPath('my-project', locationId, keyRingId, cryptoKeyId);
  const plaintext = Buffer.from('my sensitive data').toString('base64');

  const [result] = await client.encrypt({
    name: name,
    plaintext: plaintext
  });

  console.log(`Encrypted data: ${result.ciphertext}`);
}

encryptData();

Decrypt Data

This code sample demonstrates how to decrypt data that was previously encrypted using a cryptographic key. The ciphertext is decrypted and the original plaintext is returned.

const { KeyManagementServiceClient } = require('@google-cloud/kms');
const client = new KeyManagementServiceClient();

async function decryptData() {
  const locationId = 'global';
  const keyRingId = 'my-key-ring';
  const cryptoKeyId = 'my-crypto-key';
  const name = client.cryptoKeyPath('my-project', locationId, keyRingId, cryptoKeyId);
  const ciphertext = '...'; // The encrypted data

  const [result] = await client.decrypt({
    name: name,
    ciphertext: ciphertext
  });

  console.log(`Decrypted data: ${Buffer.from(result.plaintext, 'base64').toString()}`);
}

decryptData();

Other packages similar to @google-cloud/kms

Keywords

FAQs

Package last updated on 05 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc