/// <summary> /// backup the specified key and then restores the key into a vault /// </summary> /// <param name="keyName"> the name of the key to get </param> /// <returns> restored key bundle </returns> private static KeyBundle BackupRestoreKey(string keyName) { var vaultAddress = inputValidator.GetVaultAddress(); keyName = inputValidator.GetKeyName(); // Get a backup of the key and cache its backup value var backupKeyResult = keyVaultClient.BackupKeyAsync(vaultAddress, keyName).GetAwaiter().GetResult(); Console.Out.WriteLine(string.Format( "The backup key value contains {0} bytes.\nTo restore it into a key vault this value should be provided!", backupKeyResult.Value.Length)); // Get the vault address from args or use the default one var newVaultAddress = inputValidator.GetVaultAddress(); // Delete any existing key in that vault. keyVaultClient.DeleteKeyAsync(vaultAddress, keyName).GetAwaiter().GetResult(); // Restore the backed up value into the vault var restoredKey = keyVaultClient.RestoreKeyAsync(newVaultAddress, backupKeyResult.Value).GetAwaiter().GetResult(); Console.Out.WriteLine("Restored key:---------------"); PrintoutKey(restoredKey); // Cache the restored key return(restoredKey); }
public static async Task <List <BackupKeyResult> > BackupKeysAsync(List <string> secrets) { // Performs the backup and add the result into the list. var results = new List <BackupKeyResult>(); foreach (var name in secrets) { var result = await _kv.BackupKeyAsync(_baseUri, name).ConfigureAwait(false); results.Add(result); } // Returns the backup results. return(results); }