Add encrypt and decrypt data in file
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"password/output"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
type ByteReader interface {
|
||||
@@ -45,8 +47,10 @@ func NewVault(db Db, enc encrypter.Encrypter) *VaultWithDb {
|
||||
enc: enc,
|
||||
}
|
||||
}
|
||||
data := enc.Decrypt(file)
|
||||
var vault Vault
|
||||
err = json.Unmarshal(file, &vault)
|
||||
err = json.Unmarshal(data, &vault)
|
||||
color.Cyan("Найдено аккаунтов - %d", len(vault.Accounts))
|
||||
if err != nil {
|
||||
output.PrintError("Не удалось разобрать файл data.json")
|
||||
return &VaultWithDb{
|
||||
@@ -108,8 +112,9 @@ func (vault *VaultWithDb) DeleteAccountByUrl(url string) bool {
|
||||
func (vault *VaultWithDb) save() {
|
||||
vault.UpdatedAt = time.Now()
|
||||
data, err := vault.Vault.ToBytes()
|
||||
encData := vault.enc.Encrypt(data)
|
||||
if err != nil {
|
||||
output.PrintError("Не удалось преобразовать")
|
||||
}
|
||||
vault.db.Write(data)
|
||||
vault.db.Write(encData)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user