https://github.com/rubiojr/fcrypto
secretbox based file encryption/decryption
https://github.com/rubiojr/fcrypto
Last synced: 3 months ago
JSON representation
secretbox based file encryption/decryption
- Host: GitHub
- URL: https://github.com/rubiojr/fcrypto
- Owner: rubiojr
- License: mit
- Created: 2019-06-24T13:33:19.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-01T15:32:15.000Z (almost 6 years ago)
- Last Synced: 2024-04-14T17:10:25.172Z (about 1 year ago)
- Language: Go
- Size: 23.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fcrypto
[](https://travis-ci.com/rubiojr/fcrypto)
File encryption/decryption extracted from Nick Craig-Wood's [rclone source code](https://github.com/ncw/rclone).
> rclone uses nacl secretbox which in turn uses XSalsa20 and Poly1305 to encrypt and authenticate your configuration with secret-key cryptography. The password is SHA-256 hashed, which produces the key for secretbox. The hashed password is not stored.
>
> While this provides very good security, we do not recommend storing your encrypted rclone configuration in public if it contains sensitive information, maybe except if you use a very strong password.See [file encryption in rclone docs.](https://github.com/ncw/rclone/blob/976a020a2f4814ab32686bd47870ddb45699950a/docs/content/docs.md)
```go
package mainimport (
"bytes"
"fmt"
"os""github.com/rubiojr/fcrypto"
)const secret = "bar"
const file = "secret.conf"func main() {
if _, err := os.Stat(file); os.IsNotExist(err) {
fmt.Println("Saving a file with 'foobar'")
fcrypto.SaveFile(bytes.NewBufferString("foobar"), file, secret)
} else {
fmt.Println("Loading existing " + file)
}buf, err := fcrypto.LoadFile(file, secret)
if err != nil {
panic(err)
}
fmt.Println("Decrypting the file...")
fmt.Println("File content: " + buf.String())
}
```