npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kms-encrypt-obj

v0.0.4

Published

AWS Key Management Serviceを用いて、オブジェクトを暗号化・復号化するためのパッケージです。

Readme

概要

AWS Key Management Serviceを用いて、オブジェクトを暗号化・復号化するためのパッケージです。

設定ファイルなどの暗号化に使われることを想定しており、以下のような特徴があります。

  • 「指定したキーに対応するバリューのみ暗号化し、それ以外は暗号化しない」ということが可能。
  • 「コマンドラインでの暗号化・復号化」と「プログラム内からの復号化」が可能。
  • プログラム内での利用の際、同期的に(イベントループをブロックして)復号化することも可能。 module.exports とともに用いるのに便利です。これについてはプログラム起動時以外に走らせることはおすすめしません。

使い方

暗号化 (コマンドライン)

JSONを読み込み、指定されたキーに対応するバリューが暗号化されたJSONを出力します。

コマンド

kms-encrypt-obj --aws-access-key ... --aws-secret-key ... --aws-region ... --kms-key-id ... --keys-to-encrypt ... /path/to/json
  • aws-access-key, aws-secret-key, aws-region については、コマンドラインで指定する代わりに、 AWS_ACCESS_KEY, AWS_SECRET_KEY, AWS_REGION という名前の環境変数を設定することも可能です。

入力ファイル

{
  "key_a": "value_a",
  "key_b": "value_b",
  "key_c": "value_c"
}

コマンド

export AWS_ACCESS_KEY=...
export AWS_SECRET_KEY=...
export AWS_REGION=...
kms-encrypt-obj --kms-key-id ... --keys-to-encrypt key_b,key_c /path/to/json

出力

{
  "key_a": "value_a",
  "_encrypted": {
    "key_b": "value_b_encrypted",
    "key_c": "value_c_encrypted"
  }
}

標準出力に書き込まれます。

復号化 (コマンドライン)

上の暗号化によって作成されたJSONファイルを読み込み、復号化したものを出力します。

コマンド

kms-decrypt-obj --aws-access-key ... --aws-secret-key ... --aws-region ... /path/to/json

入力ファイル

{
  "key_a": "value_a",
  "_encrypted": {
    "key_b": "value_b_encrypted",
    "key_c": "value_c_encrypted"
  }
}

コマンド

export AWS_ACCESS_KEY=...
export AWS_SECRET_KEY=...
export AWS_REGION=...
kms-decrypt-obj /path/to/json

出力

{
  "key_a": "value_a",
  "key_b": "value_b",
  "key_c": "value_c"
}

プログラム内での利用

const KmsEncryptObj = require('kms-encrypt-obj');

const kmsEncryptObj = new KmsEncryptObj({
  awsAccessKey: '...',
  awsSecretKey: '...',
  awsRegion: '...',
});

kmsEncryptObj.encrypt(
  {
    key_a: 'value_a',
    key_b: 'value_b',
    key_c: 'value_c',
  },
  'kms key id',
  ['key_b', 'key_c']
)
  .then((encrypted) => {
    // encrypted: {
    //   key_a: 'value_a',
    //   _encrypted: {
    //     key_b: 'value_b_encrypted',
    //     key_c: 'value_c_encrypted',
    //   },
    // }

    return kmsEncryptObj.decrypt(encrypted);
  })
  .then((decrypted) => {
    // decrypted: {
    //   key_a: 'value_a',
    //   key_b: 'value_b',
    //   key_c: 'value_c',
    // }
  });

プログラムの起動時など、同期的に処理をしたい場合には kmsEncryptObj.decryptSync が使用できます。