forked from a2call/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt.go
21 lines (17 loc) · 967 Bytes
/
decrypt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package crypto
import (
"io"
"github.com/catalyzeio/gcm/gcm"
)
// DecryptFile takes in an ecrypted file and decrypts it to the given
// output path based on the Key and IV. The Key and IV should be the hex and
// base64 encoded version
func (c *SCrypto) DecryptFile(encryptedFilePath, key, iv, outputFilePath string) error {
return gcm.DecryptFile(encryptedFilePath, outputFilePath, c.Unhex([]byte(key), KeySize), c.Unhex([]byte(iv), IVSize), c.Unhex([]byte(gcm.AAD), AADSize))
}
// NewDecryptWriteCloser takes a io.WriteCloser and wraps it in a
// type that will decrypt Writes to the io.WriteCloser as they are written.
// The passed in key and iv should *NOT* be base64 encoded or hex encoded.
func (c *SCrypto) NewDecryptWriteCloser(writeCloser io.WriteCloser, key, iv string) (*gcm.DecryptWriteCloser, error) {
return gcm.NewDecryptWriteCloser(writeCloser, c.Unhex([]byte(key), KeySize), c.Unhex([]byte(iv), IVSize), c.Unhex([]byte(gcm.AAD), AADSize))
}