зеркало из
1
0
Форкнуть 0
This commit is contained in:
Simon Cropp 2017-07-06 10:17:06 +10:00 коммит произвёл Neeraj Makam
Родитель a8e02239ef
Коммит 9e361d7ebf
5 изменённых файлов: 15 добавлений и 15 удалений

Просмотреть файл

@ -27,5 +27,5 @@ queueClient.RegisterPlugin(keyVaultPlugin);
var message = new Message(Encoding.UTF8.GetBytes("Super secret message")); var message = new Message(Encoding.UTF8.GetBytes("Super secret message"));
await queueClient.SendAsync(message); await queueClient.SendAsync(message).ConfigureAwait(false);
``` ```

Просмотреть файл

@ -21,7 +21,7 @@ queueClient.RegisterPlugin(messageIdPlugin);
var message = new Message(Encoding.UTF8.GetBytes("Message with GUID message ID")); var message = new Message(Encoding.UTF8.GetBytes("Message with GUID message ID"));
await queueClient.SendAsync(message); await queueClient.SendAsync(message).ConfigureAwait(false);
// message.MessageId will be assigned a GUID in a 32 digit format w/o hyphens or braces // message.MessageId will be assigned a GUID in a 32 digit format w/o hyphens or braces
``` ```

Просмотреть файл

@ -84,13 +84,13 @@ namespace Microsoft.Azure.ServiceBus.KeyVault
return message; return message;
} }
var secret = await secretManager.GetHashedSecret(secretName, secretVersion); var secret = await secretManager.GetHashedSecret(secretName, secretVersion).ConfigureAwait(false);
message.UserProperties.Add(KeyVaultMessageHeaders.InitializationVectorPropertyName, base64InitializationVector); message.UserProperties.Add(KeyVaultMessageHeaders.InitializationVectorPropertyName, base64InitializationVector);
message.UserProperties.Add(KeyVaultMessageHeaders.KeyNamePropertyName, secretName); message.UserProperties.Add(KeyVaultMessageHeaders.KeyNamePropertyName, secretName);
message.UserProperties.Add(KeyVaultMessageHeaders.KeyVersionPropertyName, secretVersion); message.UserProperties.Add(KeyVaultMessageHeaders.KeyVersionPropertyName, secretVersion);
message.Body = await KeyVaultPlugin.Encrypt(message.Body, secret, this.initializationVector); message.Body = await KeyVaultPlugin.Encrypt(message.Body, secret, this.initializationVector).ConfigureAwait(false);
return message; return message;
} }
catch (Exception ex) catch (Exception ex)
@ -128,11 +128,11 @@ namespace Microsoft.Azure.ServiceBus.KeyVault
{ {
secretVersion = message.UserProperties[KeyVaultMessageHeaders.KeyVersionPropertyName] as string; secretVersion = message.UserProperties[KeyVaultMessageHeaders.KeyVersionPropertyName] as string;
message.UserProperties.Remove(KeyVaultMessageHeaders.KeyVersionPropertyName); message.UserProperties.Remove(KeyVaultMessageHeaders.KeyVersionPropertyName);
} }
var secret = await secretManager.GetHashedSecret(secretName, secretVersion); var secret = await secretManager.GetHashedSecret(secretName, secretVersion).ConfigureAwait(false);
var decryptedMessage = await KeyVaultPlugin.Decrypt(message.Body, secret, iV); var decryptedMessage = await KeyVaultPlugin.Decrypt(message.Body, secret, iV).ConfigureAwait(false);
message.Body = decryptedMessage; message.Body = decryptedMessage;
return message; return message;
@ -166,7 +166,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault
var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
return await PerformCryptography(encryptor, payload); return await PerformCryptography(encryptor, payload).ConfigureAwait(false);
} }
} }
@ -182,7 +182,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault
var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
return await PerformCryptography(decryptor, payload); return await PerformCryptography(decryptor, payload).ConfigureAwait(false);
} }
} }
@ -193,7 +193,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault
using (var cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write)) using (var cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
{ {
// Write all data to the memory stream. // Write all data to the memory stream.
await cryptoStream.WriteAsync(data, 0, data.Length); await cryptoStream.WriteAsync(data, 0, data.Length).ConfigureAwait(false);
cryptoStream.FlushFinalBlock(); cryptoStream.FlushFinalBlock();
return memoryStream.ToArray(); return memoryStream.ToArray();
} }

Просмотреть файл

@ -51,7 +51,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault
return secretCache[combinedNameAndVersion]; return secretCache[combinedNameAndVersion];
} }
var secret = await GetSecretFromKeyVault(secretName, secretVersion); var secret = await GetSecretFromKeyVault(secretName, secretVersion).ConfigureAwait(false);
using (var sha256 = SHA256.Create()) using (var sha256 = SHA256.Create())
{ {
var secretAsBytes = Encoding.UTF8.GetBytes(secret); var secretAsBytes = Encoding.UTF8.GetBytes(secret);
@ -79,11 +79,11 @@ namespace Microsoft.Azure.ServiceBus.KeyVault
SecretBundle secretResult; SecretBundle secretResult;
if (string.IsNullOrWhiteSpace(secretVersion)) if (string.IsNullOrWhiteSpace(secretVersion))
{ {
secretResult = await keyVaultClient.GetSecretAsync(this.KeyVaultUrl, secretName); secretResult = await keyVaultClient.GetSecretAsync(this.KeyVaultUrl, secretName).ConfigureAwait(false);
} }
else else
{ {
secretResult = await keyVaultClient.GetSecretAsync(this.KeyVaultUrl, secretName, secretVersion); secretResult = await keyVaultClient.GetSecretAsync(this.KeyVaultUrl, secretName, secretVersion).ConfigureAwait(false);
} }
return secretResult.Value; return secretResult.Value;
} }
@ -101,7 +101,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault
try try
{ {
var result = await ctx.AcquireTokenAsync(resource, credential); var result = await ctx.AcquireTokenAsync(resource, credential).ConfigureAwait(false);
return result.AccessToken; return result.AccessToken;
} }
catch (Exception ex) catch (Exception ex)

Просмотреть файл

@ -23,7 +23,7 @@ namespace Microsoft.Azure.ServiceBus.KeyVault.Test
using (var sha256 = SHA256.Create()) using (var sha256 = SHA256.Create())
{ {
hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(password)); hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
} }
var iV = KeyVaultPlugin.GenerateInitializationVector(); var iV = KeyVaultPlugin.GenerateInitializationVector();
var encryptedPayload = await KeyVaultPlugin.Encrypt(payload, hash, iV); var encryptedPayload = await KeyVaultPlugin.Encrypt(payload, hash, iV);