Пример #1
0
        /// <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 <string> > RestoreKeysAsync(List <BackupKeyResult> keys)
        {
            // Performs the restore and add the result into the list.
            var results = new List <KeyBundle>();

            foreach (var key in keys)
            {
                var result = await _kv.RestoreKeyAsync(_baseUri, key.Value).ConfigureAwait(false);

                results.Add(result);
            }

            // Returns the list of secret names.
            return(results.Select(p => p.KeyIdentifier.Name).ToList());
        }