github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/lib/crypto/decrypt.go (about)

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