File tree Expand file tree Collapse file tree 3 files changed +97
-0
lines changed Expand file tree Collapse file tree 3 files changed +97
-0
lines changed Original file line number Diff line number Diff line change
1
+ // <directives>
2
+ using System ;
3
+ using Azure . Identity ;
4
+ using Azure . Security . KeyVault . Secrets ;
5
+ // </directives>
6
+
7
+ namespace key_vault_console_app
8
+ {
9
+ class Program
10
+ {
11
+ static void Main ( string [ ] args )
12
+ {
13
+ string secretName = "mySecret" ;
14
+
15
+ // <authenticate>
16
+ string keyVaultName = Environment . GetEnvironmentVariable ( "KEY_VAULT_NAME" ) ;
17
+ var kvUri = "https://" + keyVaultName + ".vault.azure.net" ;
18
+
19
+ var client = new SecretClient ( new Uri ( kvUri ) , new DefaultAzureCredential ( ) ) ;
20
+ // </authenticate>
21
+
22
+ Console . Write ( "Input the value of your secret > " ) ;
23
+ string secretValue = Console . ReadLine ( ) ;
24
+
25
+ Console . Write ( "Creating a secret in " + keyVaultName + " called '" + secretName + "' with the value '" + secretValue + "` ..." ) ;
26
+
27
+ // <setsecret>
28
+ client . SetSecret ( secretName , secretValue ) ;
29
+ // </setsecret>
30
+
31
+ Console . WriteLine ( " done." ) ;
32
+
33
+ Console . WriteLine ( "Forgetting your secret." ) ;
34
+ secretValue = "" ;
35
+ Console . WriteLine ( "Your secret is '" + secretValue + "'." ) ;
36
+
37
+ Console . WriteLine ( "Retrieving your secret from " + keyVaultName + "." ) ;
38
+
39
+ // <getsecret>
40
+ Secret secret = client . GetSecret ( secretName ) ;
41
+ // </getsecret>
42
+
43
+ Console . WriteLine ( "Your secret is '" + secret . Value + "'." ) ;
44
+
45
+ Console . Write ( "Deleting your secret from " + keyVaultName + " ..." ) ;
46
+
47
+ // <deletesecret>
48
+ client . DeleteSecret ( secretName ) ;
49
+ // </deletesecret>
50
+
51
+ System . Threading . Thread . Sleep ( 5000 ) ;
52
+ Console . WriteLine ( " done." ) ;
53
+
54
+ }
55
+ }
56
+ }
Original file line number Diff line number Diff line change
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
+
3
+ <PropertyGroup >
4
+ <OutputType >Exe</OutputType >
5
+ <TargetFramework >netcoreapp2.2</TargetFramework >
6
+ </PropertyGroup >
7
+
8
+ <ItemGroup >
9
+ <PackageReference Include =" Microsoft.AspNetCore.All" Version =" 2.2.5" />
10
+ <PackageReference Include =" Microsoft.Azure.KeyVault" Version =" 3.0.3" />
11
+ <PackageReference Include =" Microsoft.Azure.Management.ResourceManager.Fluent" Version =" 1.22.2" />
12
+ <PackageReference Include =" Microsoft.IdentityModel.Clients.ActiveDirectory" Version =" 5.0.5" />
13
+ <PackageReference Include =" System.Threading.Tasks" Version =" 4.3.0" />
14
+ </ItemGroup >
15
+
16
+ </Project >
Original file line number Diff line number Diff line change
1
+
2
+ Microsoft Visual Studio Solution File, Format Version 12.00
3
+ # Visual Studio Version 16
4
+ VisualStudioVersion = 16.0.28922.388
5
+ MinimumVisualStudioVersion = 10.0.40219.1
6
+ Project ("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}" ) = "akvdotnet" , "..\..\..\source\repos\akvdotnet\akvdotnet.csproj" , "{0B0BA421-7C20-454B-9B87-0D0C70237C02}"
7
+ EndProject
8
+ Global
9
+ GlobalSection (SolutionConfigurationPlatforms ) = preSolution
10
+ Debug| Any CPU = Debug| Any CPU
11
+ Release| Any CPU = Release| Any CPU
12
+ EndGlobalSection
13
+ GlobalSection (ProjectConfigurationPlatforms ) = postSolution
14
+ {0B0BA421-7C20-454B-9B87-0D0C70237C02} .Debug| Any CPU .ActiveCfg = Debug| Any CPU
15
+ {0B0BA421-7C20-454B-9B87-0D0C70237C02} .Debug| Any CPU .Build .0 = Debug| Any CPU
16
+ {0B0BA421-7C20-454B-9B87-0D0C70237C02} .Release| Any CPU .ActiveCfg = Release| Any CPU
17
+ {0B0BA421-7C20-454B-9B87-0D0C70237C02} .Release| Any CPU .Build .0 = Release| Any CPU
18
+ EndGlobalSection
19
+ GlobalSection (SolutionProperties ) = preSolution
20
+ HideSolutionNode = FALSE
21
+ EndGlobalSection
22
+ GlobalSection (ExtensibilityGlobals ) = postSolution
23
+ SolutionGuid = {2DE801EB-F8F7-4FB7-A5F0-3BD0CB194BB5}
24
+ EndGlobalSection
25
+ EndGlobal
You can’t perform that action at this time.
0 commit comments