public async Task <DataKey> GetAsync(string name)
        {
            using (ITransaction transaction = _transactionManager.Create())
            {
                try
                {
                    if (name == MasterDataKeys.Master)
                    {
                        return(new DataKey
                        {
                            Name = MasterDataKeys.Master,
                            Value = (await _masterKeyProvider.GetAsync()).Value
                        });
                    }

                    DataKey dataKey = await _dataKeyRepository.GetSharedAsync(name) ?? await _dataKeyRepository.GetAsync(name);

                    if (dataKey == null)
                    {
                        throw new DataKeyNotFoundException(name);
                    }

                    transaction.Commit();

                    return(dataKey);
                }
                catch (Exception e)
                {
                    throw new DataKeyNotFoundException(name, e);
                }
            }
        }
Exemple #2
0
        public async Task <T> UnprotectAsync <T>(string data, string keyName)
        {
            DataKey dataKey = await _dataKeyProvider.GetAsync(keyName);

            return(_encryptionFactory.Decrypt <T>(data, dataKey.Value));
        }
Exemple #3
0
        public async Task <string> ProtectAsync <T>(T data, string keyName)
        {
            DataKey dataKey = await _dataKeyProvider.GetAsync(keyName);

            return(_encryptionFactory.Encrypt(data, dataKey.Value));
        }
Exemple #4
0
        public async Task <HashSet> StaticHashAsync(string data, string saltName)
        {
            DataKey dataKey = await _dataKeyProvider.GetAsync(saltName);

            return(await _hashFactory.GenerateHashAsync(data, Encoding.UTF8.GetString(dataKey.Value.Key)));
        }