forked from aksdb/CalAnonSync
Implemented decrypt command (fixes #2)
This commit is contained in:
parent
dfd3ae592b
commit
1844bd9e96
|
@ -6,7 +6,6 @@ import (
|
|||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"io"
|
||||
|
@ -192,8 +191,30 @@ func runSettingsEncryption(cmd *cobra.Command, args []string) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
log.Println("Settings encrypted")
|
||||
}
|
||||
|
||||
func runSettingsDecryption(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("Decrypt")
|
||||
s := LoadSettings()
|
||||
|
||||
// Rewrite the settings file.
|
||||
f, err := os.OpenFile(settingsName, os.O_WRONLY|os.O_TRUNC, 0600)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not rewrite settings: %s\n", err)
|
||||
}
|
||||
defer f.Close()
|
||||
e := json.NewEncoder(f)
|
||||
e.SetIndent("", " ")
|
||||
err = e.Encode(&s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = os.Remove(keyName)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not remove key file: %s\n", err)
|
||||
}
|
||||
|
||||
log.Println("Settings decrypted")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue