public async Task <IKey> ResolveKeyAsync(string kid, CancellationToken token) { if (_isDisposed) { throw new ObjectDisposedException("CachingKeyResolver"); } if (string.IsNullOrWhiteSpace(kid)) { throw new ArgumentNullException("kid"); } IKey result = _cache.Get(kid); if (result == null) { result = await _inner.ResolveKeyAsync(kid, token).ConfigureAwait(false); if (result != null) { // Cache the resolved key using the result's Kid. // This is especially for the case when the resolved key contains information about the key version var cacheKid = string.IsNullOrWhiteSpace(result.Kid) ? kid : result.Kid; var cachedKey = new CacheKey(result); _cache.Add(cacheKid, cachedKey); return(cachedKey); } } return(result); }
public async Task <IKey> ResolveKeyAsync(string kid, CancellationToken token) { if (_cache == null) { throw new ObjectDisposedException("CachingKeyResolver"); } if (string.IsNullOrWhiteSpace(kid)) { throw new ArgumentNullException("kid"); } IKey result = _cache.Get(kid); if (result == null) { result = await _inner.ResolveKeyAsync(kid, token).ConfigureAwait(false); if (result != null) { _cache.Add(kid, result); } } return(result); }
public async Task <Tuple <byte[], KeyValuePair <string, string> > > EncriptEvelopeData(string secretIdentifier, byte[] cleanData) { var key = await _keyResolver.ResolveKeyAsync(secretIdentifier, CancellationToken.None); if (key == null) { throw new NullReferenceException("key"); } var envelope = this.InternalEnvelopeEncription(key, cleanData); var serializedEvelope = JsonConvert.SerializeObject(envelope); var keyValuePair = new KeyValuePair <string, string>(ENCRIPTION_INFO, serializedEvelope); return(new Tuple <byte[], KeyValuePair <string, string> >(envelope.EncriptedData, keyValuePair)); }
public TableProvider(string accountName, string accountKey, string tableName, string keyId, IKeyResolver keyResolver) { var storageCredentials = new StorageCredentials(accountName, accountKey); var storageAccount = new CloudStorageAccount(storageCredentials, useHttps: true); var tableClient = storageAccount.CreateCloudTableClient(); _table = tableClient.GetTableReference(tableName); _table.CreateIfNotExists(); _requestOption = new TableRequestOptions() { EncryptionPolicy = new TableEncryptionPolicy(keyResolver.ResolveKeyAsync(keyId, CancellationToken.None).Result, null) }; _retreiveOption = new TableRequestOptions() { EncryptionPolicy = new TableEncryptionPolicy(null, keyResolver) }; }