internal static IDictionary <string, string> DecryptNameAndValues(string encrypted, string pass) { var ret = new Dictionary <string, string>(); var dec = string.Empty; try { dec = AesUtil.DecryptString(encrypted, pass); } catch (Exception e) { Logger.Warn("Can't decrypt names and values", e); return(ret); } var nvs = dec.Split(new[] { ";", }, StringSplitOptions.RemoveEmptyEntries); foreach (var nv in nvs) { var strs = nv.Split(new[] { "=", }, StringSplitOptions.RemoveEmptyEntries); if (strs != null && strs.Length == 2) { ret.Add(strs[0], strs[1]); } } return(ret); }
internal static string DecryptSmtpPassword(string encrypted) { try { return(AesUtil.DecryptString(encrypted, MemopadConsts.SmtpPasswordEncryptingPassword)); } catch (Exception e) { Logger.Warn("Smtp password decryption failed.", e); return(""); } }
/// <summary> /// Item1に日付,Item2にcountを格納して返す。 /// encryptedが想定外の値ならItem1にはtoday,Item2には0を格納。 /// </summary> internal static Tuple <DateTime, int> DecryptDateAndCount(string encrypted, DateTime today, string pass) { try { if (StringUtil.IsNullOrWhitespace(encrypted)) { return(Tuple.Create(today, 0)); } var decrypted = string.Empty; try { decrypted = AesUtil.DecryptString(encrypted, pass); } catch (Exception e) { Logger.Warn("Can't decrypt date and count", e); return(Tuple.Create(today, 0)); } var strs = decrypted.Split('#'); if (strs == null || strs.Length != 2) { return(Tuple.Create(today, 0)); } var date = default(DateTime); if (!DateTime.TryParse(strs[0], out date)) { return(Tuple.Create(today, 0)); } var count = 0; if (!int.TryParse(strs[1], out count)) { return(Tuple.Create(today, 0)); } return(Tuple.Create(date, count)); } catch (Exception) { return(Tuple.Create(today, 0)); } }
internal static Tuple <bool, Version> DecryptBoolAndVersion(string encrypted, string pass, Tuple <bool, Version> defaultValue) { if (StringUtil.IsNullOrWhitespace(encrypted)) { return(defaultValue); } var decrypted = string.Empty; try { decrypted = AesUtil.DecryptString(encrypted, pass); var strs = decrypted.Split('#'); if (strs == null || strs.Length != 2) { return(defaultValue); } return(Tuple.Create(bool.Parse(strs[0]), new Version(strs[1]))); } catch (Exception e) { Logger.Warn("Decrypt bool and version failed", e); return(defaultValue); } }
protected override void EndProcessing() { string filePath; if (Path.IsPathRooted(FilePath)) { filePath = Path.GetFullPath(FilePath); } else { filePath = Path.GetFullPath(Path.Join(SessionState.Path.CurrentLocation.Path, FilePath)); } if (!File.Exists(filePath)) { Host.UI.WriteErrorLine($"File does not exist at: {filePath}"); return; } var fileContent = File.ReadAllText(filePath); var dataJson = JObject.Parse(fileContent); string[][] accountArrayHex; if (dataJson.TryGetValue(LocalAccountsUtil.JSON_ENCRYPTED_ACCOUNTS_KEY, out var token)) { if (string.IsNullOrWhiteSpace(Password)) { Host.UI.WriteErrorLine($"No password parameter specified and accounts are encryped in file {FilePath}"); return; } var encrypedAccounts = token.Value <string>(); string decrypedContent; try { decrypedContent = AesUtil.DecryptString(encrypedAccounts, Password); } catch (Exception ex) { Host.UI.WriteErrorLine(ex.ToString()); Host.UI.WriteErrorLine("Failed to decrypt account data. Incorrect password?"); return; } accountArrayHex = JsonConvert.DeserializeObject <string[][]>(decrypedContent); } else { if (!string.IsNullOrWhiteSpace(Password)) { Host.UI.WriteErrorLine($"Password parameter specified but accounts are encryped in file {FilePath}"); return; } accountArrayHex = dataJson[LocalAccountsUtil.JSON_ACCOUNTS_KEY].ToObject <string[][]>(); } var accounts = accountArrayHex .Select(a => EthereumEcdsa.Create(HexUtil.HexToBytes(a[1]), EthereumEcdsaKeyType.Private)) .Select(a => (a.EcdsaKeyPairToAddress(), a)) .ToArray(); GlobalVariables.AccountKeys = accounts; Host.UI.WriteLine($"Loaded {accounts.Length} accounts from {filePath}"); }