private static async Task RunSample() { var keyVaultClient = new KeyVaultClient(GetAccessToken); // create a key :) var keyCreate = await keyVaultClient.CreateKeyAsync( vault : _keyVaultUrl, keyName : _keyVaultEncryptionKeyName, keyType : _keyType, keyAttributes : new KeyAttributes() { Enabled = true, Expires = UnixEpoch.FromUnixTime(int.MaxValue), NotBefore = UnixEpoch.FromUnixTime(0), }, tags : new Dictionary <string, string> { { "purpose", "StackOverflow Demo" } }); Console.WriteLine(string.Format( "Created {0} ", keyCreate.KeyIdentifier.Name)); // retrieve the key var keyRetrieve = await keyVaultClient.GetKeyAsync( _keyVaultUrl, _keyVaultEncryptionKeyName); Console.WriteLine(string.Format( "Retrieved {0} ", keyRetrieve.KeyIdentifier.Name)); }
private KeyBundle GenerateKeyBundle() { return(new KeyBundle { Key = new JsonWebKey() { Kty = JsonWebKeyType.EllipticCurve }, Attributes = new KeyAttributes() { Enabled = true, Expires = UnixEpoch.FromUnixTime(int.MaxValue), NotBefore = UnixEpoch.FromUnixTime(0), } }); }
/// <summary> /// Creates a key bundle from an existing JSON web key. /// </summary> /// <param name="key">The key to import. Must contain public and private components.</param> /// <param name="enabled">Initial 'enabled' state.</param> /// <param name="notBefore">Key cannot be used before this time.</param> /// <param name="notAfter">Key cannot be used after this time.</param> /// <returns>A KeyBundle.</returns> protected static KeyBundle GetImportKeyBundle(JsonWebKey key, bool enabled = true, int notBefore = 0, int notAfter = int.MaxValue) { return(new KeyBundle { Key = key, Attributes = new KeyAttributes() { Enabled = enabled, Expires = UnixEpoch.FromUnixTime(notAfter), NotBefore = UnixEpoch.FromUnixTime(notBefore), }, Tags = new Dictionary <string, string>() { { "purpose", "unit test" } } }); }
/// <summary> /// Gets the import key bundle /// </summary> /// <returns> key bundle </returns> internal KeyBundle GetImportKeyBundle() { var rsa = new RSACryptoServiceProvider(2048); var webKey = CreateJsonWebKey(rsa.ExportParameters(true)); // Default import Key Bundle var importKeyBundle = new KeyBundle { Key = webKey, Attributes = new KeyAttributes() { Enabled = true, Expires = UnixEpoch.FromUnixTime(int.MaxValue), NotBefore = UnixEpoch.FromUnixTime(0), } }; return(importKeyBundle); }
/// <summary> /// Gets key bundle from args or uses a default key bundle /// </summary> /// <param name="args"> the input arguments of the console program </param> /// <returns> key bundle </returns> public KeyBundle GetKeyBundle() { // Default Key Bundle var defaultKeyBundle = new KeyBundle { Key = new JsonWebKey() { Kty = GetKeyType(), }, Attributes = new KeyAttributes() { Enabled = true, Expires = UnixEpoch.FromUnixTime(int.MaxValue), NotBefore = UnixEpoch.FromUnixTime(0), } }; return(defaultKeyBundle); }