mirror of https://github.com/schollz/croc.git
need to export encryption
This commit is contained in:
parent
7d9b199ca3
commit
a7f12ca179
|
@ -9,15 +9,15 @@ import (
|
||||||
"golang.org/x/crypto/pbkdf2"
|
"golang.org/x/crypto/pbkdf2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type encryption struct {
|
type Encryption struct {
|
||||||
key []byte
|
key []byte
|
||||||
passphrase []byte
|
passphrase []byte
|
||||||
salt []byte
|
salt []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// New generates a new encryption, using the supplied passphrase and
|
// New generates a new Encryption, using the supplied passphrase and
|
||||||
// an optional supplied salt.
|
// an optional supplied salt.
|
||||||
func New(passphrase []byte, salt []byte) (e encryption, err error) {
|
func New(passphrase []byte, salt []byte) (e Encryption, err error) {
|
||||||
e.passphrase = passphrase
|
e.passphrase = passphrase
|
||||||
if salt == nil {
|
if salt == nil {
|
||||||
e.salt = make([]byte, 8)
|
e.salt = make([]byte, 8)
|
||||||
|
@ -31,12 +31,12 @@ func New(passphrase []byte, salt []byte) (e encryption, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e encryption) Salt() []byte {
|
func (e Encryption) Salt() []byte {
|
||||||
return e.salt
|
return e.salt
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encrypt will generate an encryption, prefixed with the IV
|
// Encrypt will generate an Encryption, prefixed with the IV
|
||||||
func (e encryption) Encrypt(plaintext []byte) (encrypted []byte, err error) {
|
func (e Encryption) Encrypt(plaintext []byte) (encrypted []byte, err error) {
|
||||||
// generate a random iv each time
|
// generate a random iv each time
|
||||||
// http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
|
// http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
|
||||||
// Section 8.2
|
// Section 8.2
|
||||||
|
@ -55,8 +55,8 @@ func (e encryption) Encrypt(plaintext []byte) (encrypted []byte, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrypt an encryption
|
// Decrypt an Encryption
|
||||||
func (e encryption) Decrypt(encrypted []byte) (plaintext []byte, err error) {
|
func (e Encryption) Decrypt(encrypted []byte) (plaintext []byte, err error) {
|
||||||
b, err := aes.NewCipher(e.key)
|
b, err := aes.NewCipher(e.key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue