Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonfriesen/secretbox
https://github.com/jonfriesen/secretbox
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jonfriesen/secretbox
- Owner: jonfriesen
- Created: 2020-05-04T19:13:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-04T23:00:16.000Z (over 4 years ago)
- Last Synced: 2024-05-08T17:36:55.203Z (6 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# secret box
This is a wrapper using the [crypto/nacl/secretbox](https://godoc.org/golang.org/x/crypto/nacl/secretbox) library as a easy to use symmetric encryption to string format with everything you need to decrypt.The secrets are encrypted using ([NaCl](http://nacl.cr.yp.to/) [Secret Box](http://nacl.cr.yp.to/secretbox.html):
[Salsa20](http://en.wikipedia.org/wiki/Salsa20) +
[Poly1305-AES](http://en.wikipedia.org/wiki/Poly1305-AES)).The encrypted values are returned as a box with all the values needed to decrypt it included with the correct key. It's important the the consumer of this library implement a method to store the key securely and keep track of which key goes to which ciphertext.
### Usage
```go
// generate a key
key := crypto.Key{}
err := key.Generate()
handleError(err)// encrypt you a payload
ciphertext, err := key.Encrypt([]byte("hello, world!"))
handleError(err)// decrypt some ciphertext
plaintext, err := key.Decrypt(ciphertext)
handleError(err)fmt.Println("key", string(key.Bytes())) // stdout:
fmt.Println("text", string(plaintext)) // stdout: text hello, world!```
### Kudos
The structure of `/crypto` is inspired by the [Shopify/ejson crypto wrapper](https://github.com/Shopify/ejson/tree/master/crypto).