public void ChangePassword(string oldPassword, string newPassword) { SettingComponent sComponent = new SettingComponent(); var setting = sComponent.GetSetting(); if (MD5Helper.EncryptTo32(oldPassword) == setting.PassCiphertext) { var aclist = AccountDac.Default.SelectAll(); foreach (var item in aclist) { item.PrivateKey = AES128.Decrypt(item.PrivateKey, oldPassword); item.PrivateKey = AES128.Encrypt(item.PrivateKey, newPassword); } try { AccountDac.Default.UpdatePrivateKeyAr(aclist); setting = sComponent.GetSetting(); setting.Encrypt = true; setting.PassCiphertext = MD5Helper.EncryptTo32(newPassword); sComponent.SaveSetting(setting); } catch (Exception ex) { throw new CommonException(ErrorCode.Engine.Wallet.DB.EXECUTE_SQL_ERROR, ex); } } else { throw new CommonException(ErrorCode.Engine.Wallet.CHECK_PASSWORD_ERROR); } }
public bool EncryptWallet(string salt) { bool result = false; var aclist = AccountDac.Default.SelectAll(); foreach (var item in aclist) { item.PrivateKey = AES128.Encrypt(item.PrivateKey, salt); } try { AccountDac.Default.UpdatePrivateKeyAr(aclist); SettingComponent sComponent = new SettingComponent(); var setting = sComponent.GetSetting(); setting.Encrypt = true; setting.PassCiphertext = MD5Helper.EncryptTo32(salt); sComponent.SaveSetting(setting); result = true; } catch (Exception ex) { throw new CommonException(ErrorCode.Engine.Wallet.DB.EXECUTE_SQL_ERROR, ex); } return(result); }
public bool CheckPassword(string password) { SettingComponent sComponent = new SettingComponent(); var setting = sComponent.GetSetting(); if (MD5Helper.EncryptTo32(password) == setting.PassCiphertext) { return(true); } else { return(false); } }
public bool RestoreWalletBackup(string filePath, string salt) { bool result = false; string extensionName = Path.GetExtension(filePath).ToLower(); var setting = new SettingComponent().GetSetting(); if (setting.Encrypt && string.IsNullOrEmpty(salt)) { throw new CommonException(ErrorCode.Engine.Wallet.CHECK_PASSWORD_ERROR); } if (setting.Encrypt && (extensionName != encryptExtensionName)) { throw new CommonException(ErrorCode.Engine.Wallet.IO.EXTENSION_NAME_NOT_SUPPORT); } else if (!setting.Encrypt && extensionName != noEncryptExtensionName) { throw new CommonException(ErrorCode.Engine.Wallet.IO.EXTENSION_NAME_NOT_SUPPORT); } //Load backup file data. WalletBackup backup = null; if (extensionName == noEncryptExtensionName) { try { backup = LoadFile <WalletBackup>(filePath); } catch { var backup1 = LoadFile <WalletBackup1>(filePath); backup = backup1.ToBackup(); } } else { try { backup = LoadFile <WalletBackup>(filePath, salt); } catch { var backup1 = LoadFile <WalletBackup1>(filePath, salt); backup = backup1.ToBackup(); } backup.AccountList.RemoveAll(x => string.IsNullOrEmpty(x.PrivateKey)); } //Create SQL Query Script and run try { if (backup != null) { WalletBackupDac dac = WalletBackupDac.Default; dac.Restore(backup); result = true; } } catch (Exception ex) { throw new CommonException(ErrorCode.Engine.Wallet.DB.EXECUTE_SQL_ERROR, ex); } return(result); }