Added backend
This commit is contained in:
25
gswi.CredentialManager/Base64.cs
Normal file
25
gswi.CredentialManager/Base64.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace gswi.CredentialManager
|
||||
{
|
||||
public static class Base64
|
||||
{
|
||||
public static string Encode(string credentials)
|
||||
{
|
||||
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(credentials);
|
||||
return System.Convert.ToBase64String(plainTextBytes);
|
||||
}
|
||||
|
||||
public static string Decode(string credentials)
|
||||
{
|
||||
var base64EncodedBytes = System.Convert.FromBase64String(credentials);
|
||||
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
|
||||
}
|
||||
|
||||
public static string DecodeConnectionString(string connectionString, string credentials)
|
||||
{
|
||||
string decodedCredentials = Decode(credentials);
|
||||
return connectionString += $"password={decodedCredentials};";
|
||||
}
|
||||
}
|
||||
}
|
89
gswi.CredentialManager/Program.cs
Normal file
89
gswi.CredentialManager/Program.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using gswi.Configuration;
|
||||
|
||||
namespace gswi.CredentialManager
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static IConfiguration Configuration { get; set; }
|
||||
|
||||
static void Menu()
|
||||
{
|
||||
bool end = false;
|
||||
while (!end)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("Credential Manager: \n");
|
||||
Console.WriteLine("[1] Encode");
|
||||
Console.WriteLine("[2] Decode");
|
||||
Console.WriteLine("[x] Exit");
|
||||
Console.Write("\n> ");
|
||||
string input = Console.ReadLine();
|
||||
switch (input)
|
||||
{
|
||||
case "1":
|
||||
Console.Clear();
|
||||
Encode();
|
||||
break;
|
||||
|
||||
case "2":
|
||||
Console.Clear();
|
||||
Decode();
|
||||
break;
|
||||
|
||||
case "x":
|
||||
end = true;
|
||||
Continue();
|
||||
break;
|
||||
|
||||
case "X":
|
||||
end = true;
|
||||
Continue();
|
||||
break;
|
||||
|
||||
default:
|
||||
Console.WriteLine("Invalid input");
|
||||
Continue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Continue()
|
||||
{
|
||||
Console.WriteLine("\n\nPress any key to continue...");
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Menu();
|
||||
}
|
||||
|
||||
static void Encode()
|
||||
{
|
||||
Console.Write("String to encode: ");
|
||||
string input = Console.ReadLine();
|
||||
Console.WriteLine($"{input} encoded with Base64 is: {Base64.Encode(input)}");
|
||||
Continue();
|
||||
}
|
||||
|
||||
static void Decode()
|
||||
{
|
||||
Console.Write("String to decode: ");
|
||||
string input = Console.ReadLine();
|
||||
Console.WriteLine($"{input} decoded with Base64 is: {Base64.Decode(input)}");
|
||||
Continue();
|
||||
}
|
||||
|
||||
|
||||
protected static SettingType GetTypedSettingsFromSection<SettingType>(string sectionName) where SettingType : new()
|
||||
{
|
||||
var settings = new SettingType();
|
||||
Configuration.GetSection(sectionName).Bind(settings);
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
}
|
14
gswi.CredentialManager/gswi.CredentialManager.csproj
Normal file
14
gswi.CredentialManager/gswi.CredentialManager.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0"/>
|
||||
<PackageReference Include="NLog" Version="4.7.13"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\gswi.Configuration\gswi.Configuration.csproj"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user