Shopify / ejson

EJSON is a small library to manage encrypted secrets using asymmetric encryption.
MIT License
1.34k stars 62 forks source link

Feat/json-array #38

Closed aprubikloud closed 3 months ago

aprubikloud commented 7 years ago

Hey! I've been using ejson recently and think it's great. For my use case, the ability to encrypt/decrypt a single file with different key pairs was needed.

This PR adds the ability for ejson to decrypt/encrypt json arrays.

I also added a flag -m to decrypt. When using this flag, ejson will immediately return the first decryptable object it finds. Meaning, if I try to decrypt an array with many different public keys, but my machine only knows one of them, I will only receive the object which I could decrypt.

Usage examples (I've added these to the README):

$ ejson encrypt foo.json
$ cat foo.json
[{
  "_public_key": "63ccf05a9492e68e12eeb1c705888aebdcc0080af7e594fc402beb24cce9d14f",
  "database_password": "EJ[1:WpvX5/jG+1cU+PjzTDOVlmHkjpFhf+lFo2WWF+RiMGg=:2vIWOra8nFY1ANRdQTz+ZowBmBBV/Vj1:epXERS3pn1VDc4Gi/Zqkh+R2xM1cQFkShLF3Rg==]"
}, {
  "_public_key": "53393332c6c7c474af603c078f5696c8fe16677a09a711bba299a6c1c1676a59",
  "database_password": "EJ[1:irzmtBYYxle/5Z9FpLJHwWcMKl1xqH/UvFrN9nA6KnI=:qrYZxuC7rgpvsoDEP9vxi5TLrb9Iccjy:dRvXLkDNkqjK/02D8m4co6WWpKpC6iejtdLxDA==]"
}]
$ ejson decrypt foo.ejson
[{
  "_public_key": "63ccf05a9492e68e12eeb1c705888aebdcc0080af7e594fc402beb24cce9d14f",
  "database_password": "1234password"
}, {
  "_public_key": "53393332c6c7c474af603c078f5696c8fe16677a09a711bba299a6c1c1676a59",
  "database_password": "4321password"
}]
$ ejson decrypt -m foo.ejson
{
  "_public_key": "63ccf05a9492e68e12eeb1c705888aebdcc0080af7e594fc402beb24cce9d14f",
  "database_password": "1234password"
}

Notes:

thepwagner commented 3 months ago

Greeting from the future! This is very stale and has a lot of conflicts, I'm going to close it.