gipher

package module
v0.0.0-...-88998e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2017 License: MIT Imports: 13 Imported by: 0

README

gipher

Build Status

gipher encrypts/decrypts structured text by password or aws-kms.

plaintext, json, yaml, and toml are supported.

Usage

password

$ cat test.json
{
    "aaa": "aaa",
    "bbb": 111,
    "ccc": {
        "ddd": 222,
        "eee": "eee",
        "fff": "fff"
    }
}

$ gipher encrypt \
  --format json \
  -f test.json \
  --pattern ccc | jq
password:
{
  "aaa": "aaa",
  "bbb": 111,
  "ccc": {
    "ddd": "K0A/f1sRtp4S+N3kR6lzqYtbkEMYVSdZKeTPy1Wy",
    "eee": "l0LzhRzjhQtNaTV9K0I3AOSjD1iz9mblhas=",
    "fff": "Exbc9NPnNEI8YviY5dxP+bL6kX88ELap2NU="
  }
}

% gipher decrypt \
  --format json \
  -f encrypted.json \
  --pattern ccc | jq
password:
{
  "aaa": "aaa",
  "bbb": 111,
  "ccc": {
    "ddd": 222,
    "eee": "eee",
    "fff": "fff"
  }
}

aws-kms

$ AWS_PROFILE=default gipher encrypt \
  --format json \
  -f test.json \
  --pattern ccc \
  --cryptor aws-kms \
  --aws-region ap-northeast-1 \
  --aws-key-id alias/test | jq
{
  "aaa": "aaa",
  "bbb": 111,
  "ccc": {
    "ddd": "AQECAHgFgSrBGtkzwv+6O00BGF+UANW5TVR8ZU9AZNzY3rHwJAAAAGwwagYJKoZIhvcNAQcGoF0wWwIBADBWBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDKIkqftKQtB/HXLpGwIBEIAp4xqp5lcku4UouJ2SnKZBD773pzT8QptKY1b1PpsP1mMDhmclGqO/LN0=",
    "eee": "AQECAHgFgSrBGtkzwv+6O00BGF+UANW5TVR8ZU9AZNzY3rHwJAAAAGgwZgYJKoZIhvcNAQcGoFkwVwIBADBSBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDApjQ5SA15J08L7++AIBEIAlfKUxD8gpe5t1cHQHeYOE5SgEMPy2fU+iDnQL9e9xPBURbHYsCw==",
    "fff": "AQECAHgFgSrBGtkzwv+6O00BGF+UANW5TVR8ZU9AZNzY3rHwJAAAAGgwZgYJKoZIhvcNAQcGoFkwVwIBADBSBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDPBRIWYH3xZ4a3CRxQIBEIAli7hPcTXkkxF+lJrMhKD4DekZyiiz4vbxz6zfG0dPCPaXp+xOdQ=="
  }
}

$ AWS_PROFILE=default gipher decrypt \
  --format json \
  -f encrypted.json \
  --pattern ccc \
  --cryptor aws-kms \
  --aws-region ap-northeast-1 | jq
{
  "aaa": "aaa",
  "bbb": 111,
  "ccc": {
    "ddd": 222,
    "eee": "eee",
    "fff": "fff"
  }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCannotReadPassword = errors.New("cannot read the password. use GIPHER_PASSWORD to set the password if you did not use a terminal.")
	ErrPasswordIsEmpty    = errors.New("password is empty")
)

Functions

func DecodeCiphertext

func DecodeCiphertext(text Ciphertext) ([]byte, error)

Types

type Ciphertext

type Ciphertext []byte

Ciphertext is base64-encoded string

func EncodeCiphertext

func EncodeCiphertext(bs []byte) Ciphertext

type Cryptor

type Cryptor interface {
	// Encrypt encrypts a text and encodes it by base64.
	Encrypt(plaintext string) (Ciphertext, error)

	// Decrypt decodes a text by base64 and decrypts it.
	Decrypt(ciphertext Ciphertext) (string, error)
}

Cryptor encrypts/decrypts a text.

func NewAWSKMSCryptor

func NewAWSKMSCryptor(region string, keyID string) (Cryptor, error)

func NewPasswordCryptor

func NewPasswordCryptor(password []byte) Cryptor

func NewPasswordCryptorWithPrompt

func NewPasswordCryptorWithPrompt() (Cryptor, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL