executeEncrypt loads the config, encrypts plaintext passwords, and writes back.
()
| 92 | |
| 93 | // executeEncrypt loads the config, encrypts plaintext passwords, and writes back. |
| 94 | func executeEncrypt() { |
| 95 | configuration, err := config.LoadConfig() |
| 96 | if err != nil { |
| 97 | fatalFn(err) |
| 98 | return |
| 99 | } |
| 100 | |
| 101 | count := countPlaintextPasswords(configuration) |
| 102 | if count == 0 { |
| 103 | fmt.Println("No passwords to encrypt") |
| 104 | utils.ClearMasterKey() |
| 105 | return |
| 106 | } |
| 107 | |
| 108 | if err := config.UpdateConfig(configuration); err != nil { |
| 109 | fatalFn("Failed to write encrypted config:", err) |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | utils.ClearMasterKey() |
| 114 | fmt.Printf("Encrypted %d password(s) successfully\n", count) |
| 115 | fmt.Println("Remember your master password — it cannot be recovered if lost") |
| 116 | } |
| 117 | |
| 118 | // countPlaintextPasswords counts password fields that are non-empty and not yet encrypted. |
| 119 | func countPlaintextPasswords(c *config.MainConfig) int { |