public async Task <string> DecryptAsync(string orgId = null, SymmetricCryptoKey key = null) { if (_decryptedValue != null) { return(_decryptedValue); } var cryptoService = ServiceContainer.Resolve <ICryptoService>("cryptoService"); try { if (key == null) { key = await cryptoService.GetOrgKeyAsync(orgId); } _decryptedValue = await cryptoService.DecryptToUtf8Async(this, key); } catch { _decryptedValue = "[error: cannot decrypt]"; } return(_decryptedValue); }
protected async Task <V> DecryptObjAsync <V, D>(V viewModel, D domain, HashSet <string> map, string orgId, SymmetricCryptoKey key = null) where V : View.View { var viewModelType = viewModel.GetType(); var domainType = domain.GetType(); async Task decCsAndSetDec(string propName) { var domainPropInfo = domainType.GetProperty(propName); string val = null; if (domainPropInfo.GetValue(domain) is CipherString domainProp) { val = await domainProp.DecryptAsync(orgId, key); } var viewModelPropInfo = viewModelType.GetProperty(propName); viewModelPropInfo.SetValue(viewModel, val, null); }; var tasks = new List <Task>(); foreach (var prop in map) { tasks.Add(decCsAndSetDec(prop)); } await Task.WhenAll(tasks); return(viewModel); }
public Task <SendFileView> DecryptAsync(SymmetricCryptoKey key) => DecryptObjAsync(new SendFileView(this), this, new HashSet <string> { "FileName" }, null, key);