Remove legacy AttackTracer repo content
Some checks failed
OfficeCom Sentinel Client / build-client (push) Has been cancelled
Some checks failed
OfficeCom Sentinel Client / build-client (push) Has been cancelled
This commit is contained in:
28
src/OCSentinelCli/Security/ProtectedSecretStore.cs
Normal file
28
src/OCSentinelCli/Security/ProtectedSecretStore.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace OCSentinelCli.Security;
|
||||
|
||||
internal static class ProtectedSecretStore
|
||||
{
|
||||
public static string LoadSecret(string path)
|
||||
{
|
||||
byte[] protectedBytes = File.ReadAllBytes(path);
|
||||
byte[] plainBytes = ProtectedData.Unprotect(protectedBytes, null, DataProtectionScope.LocalMachine);
|
||||
return Encoding.UTF8.GetString(plainBytes);
|
||||
}
|
||||
|
||||
public static void SaveSecret(string path, string secret)
|
||||
{
|
||||
string fullPath = Path.GetFullPath(path);
|
||||
string? directory = Path.GetDirectoryName(fullPath);
|
||||
if (!string.IsNullOrWhiteSpace(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
byte[] plainBytes = Encoding.UTF8.GetBytes(secret);
|
||||
byte[] protectedBytes = ProtectedData.Protect(plainBytes, null, DataProtectionScope.LocalMachine);
|
||||
File.WriteAllBytes(fullPath, protectedBytes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user