-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Command for encrypting using GCP KMS
- Loading branch information
1 parent
bcbabe6
commit 368eecf
Showing
10 changed files
with
494 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.json | ||
charts | ||
bin | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package encryption | ||
|
||
import "github.com/dfernandezm/myiac/app/util" | ||
|
||
type Encrypter interface { | ||
Encrypt(plainText string) (string, error) | ||
Decrypt(cipherText string) (string, error) | ||
} | ||
|
||
type encryptionService struct { | ||
encrypter Encrypter | ||
} | ||
// NewEncryptionService create a new encrypter | ||
func NewEncrypter(encrypter Encrypter) *encryptionService { | ||
enc := new(encryptionService) | ||
enc.encrypter = encrypter | ||
return enc | ||
} | ||
|
||
// EncryptFileContents encrypts the text contained in 'filename' and returns cipherText | ||
// into a file with the same name ended with '.enc' | ||
func (enc encryptionService) EncryptFileContents(filename string) string { | ||
plainText, _ := util.ReadFileToString(filename) | ||
cipherText, _ := enc.encrypter.Encrypt(plainText) | ||
cipherTextFilename := filename + ".enc" | ||
_ = util.WriteStringToFile(cipherText, cipherTextFilename) | ||
return cipherTextFilename | ||
} | ||
|
||
// DecryptFileContents decrypts the ciphertext contained in 'filename' and returns the | ||
// plaintext result into another file with same name ended with '.dec' | ||
func (enc encryptionService) DecryptFileContents(filename string) string { | ||
cipherText, _ := util.ReadFileToString(filename) | ||
plainText, _ := enc.encrypter.Decrypt(cipherText) | ||
plainTextFilename := filename + ".dec" | ||
_ = util.WriteStringToFile(plainText, plainTextFilename) | ||
return plainTextFilename | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.