Exemplo n.º 1
0
 internal static string EncryptSmtpPassword(string raw)
 {
     try {
         return(AesUtil.EncryptString(raw, MemopadConsts.SmtpPasswordEncryptingPassword));
     } catch (Exception e) {
         Logger.Warn("Smtp password encryption failed.", e);
         return("");
     }
 }
Exemplo n.º 2
0
        internal static string EncryptNameAndValues(IDictionary <string, string> dict, string pass)
        {
            var buf = new StringBuilder();

            foreach (var pair in dict)
            {
                buf.Append(pair.Key + "=" + pair.Value + ";");
            }

            return(AesUtil.EncryptString(buf.ToString(), pass));
        }
Exemplo n.º 3
0
        protected override void EndProcessing()
        {
            if (GlobalVariables.AccountKeys == null || GlobalVariables.AccountKeys.Length == 0)
            {
                Host.UI.WriteErrorLine($"No accounts are loaded. Use '{CmdLetExtensions.GetCmdletName<NewAccountsCommand>()}' to generate accounts.");
                return;
            }

            string filePath;

            if (Path.IsPathRooted(FilePath))
            {
                filePath = Path.GetFullPath(FilePath);
            }
            else
            {
                filePath = Path.GetFullPath(Path.Join(SessionState.Path.CurrentLocation.Path, FilePath));
            }

            if (EncryptData && string.IsNullOrWhiteSpace(Password))
            {
                Host.UI.WriteErrorLine($"No '{nameof(Password)}' parameter is provided. To write without encryption set the '{nameof(EncryptData)}' parameter to false");
                return;
            }

            if (!string.IsNullOrWhiteSpace(Password) && !EncryptData)
            {
                Host.UI.WriteErrorLine($"The '{nameof(EncryptData)}' parameter is set to false but the '{nameof(Password)}' parameter is provided. Pick one.");
                return;
            }

            var accounts = GlobalVariables.AccountKeys;

            var accountArrayHex = accounts
                                  .Select(a => new[]
            {
                a.Address.ToString(hexPrefix: true),
                HexUtil.GetHexFromBytes(a.Account.ToPrivateKeyArray(), hexPrefix: true)
            })
                                  .ToArray();

            JObject dataObj = new JObject();

            if (EncryptData)
            {
                var accountJson            = JsonConvert.SerializeObject(accountArrayHex, Formatting.Indented);
                var encrypedAccountsString = AesUtil.EncryptString(accountJson, Password);
                dataObj[LocalAccountsUtil.JSON_ENCRYPTED_ACCOUNTS_KEY] = encrypedAccountsString;
            }
            else
            {
                dataObj[LocalAccountsUtil.JSON_ACCOUNTS_KEY] = JArray.FromObject(accountArrayHex);
            }

            if (File.Exists(filePath))
            {
                var choices = new Collection <ChoiceDescription>(new[]
                {
                    new ChoiceDescription("Cancel"),
                    new ChoiceDescription("Overwrite")
                });
                var overwrite = Host.UI.PromptForChoice($"File already exists at {filePath}", "Continue and overwite existing file?", choices, 0);
                if (overwrite != 1)
                {
                    Host.UI.WriteErrorLine("Accounts not saved to file.");
                    return;
                }
            }

            var dataJson = dataObj.ToString(Formatting.Indented);

            File.WriteAllText(filePath, dataJson);

            if (EncryptData)
            {
                Host.UI.WriteLine($"Wrote {accounts.Length} encrypted accounts to: {filePath}");
            }
            else
            {
                Host.UI.WriteLine($"Wrote {accounts.Length} unencrypted accounts to: {filePath}");
            }
        }
Exemplo n.º 4
0
        internal static string EncryptDateAndCount(DateTime date, int count, string pass)
        {
            var s = date.ToString("yyyy/MM/dd") + "#" + count.ToString();

            return(AesUtil.EncryptString(s, pass));
        }
Exemplo n.º 5
0
        // ========================================
        // static method
        // ========================================
        internal static string EncryptBoolAndVersion(bool b, Version version, string pass)
        {
            var s = b.ToString() + "#" + version.ToString();

            return(AesUtil.EncryptString(s, pass));
        }