Documentation
¶
Overview ¶
Package ejson implements the primary interface to interact with ejson documents and keypairs. The CLI implemented by cmd/ejson is a fairly thin wrapper around this package.
Index ¶
- func Decrypt(in io.Reader, out io.Writer, keydir string, userSuppliedPrivateKey string) error
- func DecryptFile(filePath, keydir, userSuppliedPrivateKey string) ([]byte, error)
- func Encrypt(in io.Reader, out io.Writer) (int, error)
- func EncryptFileInPlace(filePath string) (int, error)
- func GenerateKeypair() (pub string, priv string, err error)
- func GenerateKeypairForScheme(scheme string) (pub string, priv string, keyID string, err error)
- func KeyIDForPublicKey(pub string) (string, error)
- func Reencrypt(in io.Reader, out io.Writer, ...) (int, error)
- func ReencryptFileInPlace(filePath, keydir, userSuppliedPrivateKey, newPublicKey string) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
Decrypt reads an ejson stream from 'in' and writes the decrypted data to 'out'. For v1 files, the private key is looked up at <keydir>/<64-hex pubkey>. For v2 files, the 32-byte HPKE seed (64 hex chars) is looked up at <keydir>/ejv2-<SHA-384 hex> and verified against _public_key.
func DecryptFile ¶
DecryptFile decrypts filePath and returns the plaintext JSON bytes.
func Encrypt ¶
Encrypt reads all contents from 'in', extracts the pubkey and encrypts any unencrypted string values, writing the result to 'out'.
func EncryptFileInPlace ¶
EncryptFileInPlace encrypts any unencrypted fields in filePath in place.
func GenerateKeypair ¶
GenerateKeypair creates a legacy v1 Curve25519 keypair, returning hex strings.
func GenerateKeypairForScheme ¶ added in v1.7.0
GenerateKeypairForScheme creates a new ejson keypair for the named scheme ("v1" or "v2"). pub goes into _public_key, priv is the 64-hex private key (or HPKE seed for v2), and keyID is the filename/secret ID used for lookup (the 64-hex public key for v1; "ejv2-" + SHA-384 hex for v2, 101 chars).
func KeyIDForPublicKey ¶ added in v1.7.0
KeyIDForPublicKey computes the keydir / Secret Manager key identifier for a v1 or v2 _public_key string.
func Reencrypt ¶ added in v1.7.0
func Reencrypt(in io.Reader, out io.Writer, keydir, userSuppliedPrivateKey, newPublicKey string) (int, error)
Reencrypt decrypts all values in 'in', optionally switches _public_key to newPublicKey (for whole-file v1 -> v2 migration or key rotation), and re-encrypts every value for the resulting recipient. For a v2 input, the old session fields are replaced by a single fresh session.
Nothing is written to 'out' if the input is refused: when _public_key appears more than once, when a v1 input being migrated to v2 already uses the _ejson_v2_session_ prefix for its own top-level fields, or when a v2 input has a skipped (_-prefixed) field referencing a session being removed.
func ReencryptFileInPlace ¶ added in v1.7.0
func ReencryptFileInPlace(filePath, keydir, userSuppliedPrivateKey, newPublicKey string) (int, error)
ReencryptFileInPlace decrypts and re-encrypts filePath in place, optionally migrating it to newPublicKey and compacting v2 sessions down to one.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
ejson
command
|
|
|
Package crypto implements a simple convenience wrapper around golang.org/x/crypto/nacl/box.
|
Package crypto implements a simple convenience wrapper around golang.org/x/crypto/nacl/box. |
|
Package json implements functions to load the Public key data from an EJSON file, and to walk that data file, encrypting or decrypting any keys which, according to the specification, are marked as encryptable (see README.md for details).
|
Package json implements functions to load the Public key data from an EJSON file, and to walk that data file, encrypting or decrypting any keys which, according to the specification, are marked as encryptable (see README.md for details). |
