Update: Full E2EE + Scripts
This commit is contained in:
@@ -2,19 +2,36 @@ namespace RelayClient.Crypto;
|
||||
|
||||
public static class KeyStorage
|
||||
{
|
||||
private static string GetKeyFolder()
|
||||
{
|
||||
var folder = Path.Combine(FileSystem.AppDataDirectory, "keys");
|
||||
Directory.CreateDirectory(folder);
|
||||
return folder;
|
||||
}
|
||||
|
||||
public static void SavePrivateKey(string username, string privateKey)
|
||||
{
|
||||
Directory.CreateDirectory("keys");
|
||||
File.WriteAllText(Path.Combine("keys", $"{username}.private.key"), privateKey);
|
||||
File.WriteAllText(Path.Combine(GetKeyFolder(), $"{username}.private.key"), privateKey);
|
||||
}
|
||||
|
||||
public static void SavePublicKey(string username, string publicKey)
|
||||
{
|
||||
File.WriteAllText(Path.Combine(GetKeyFolder(), $"{username}.public.key"), publicKey);
|
||||
}
|
||||
|
||||
public static string LoadPrivateKey(string username)
|
||||
{
|
||||
return File.ReadAllText(Path.Combine("keys", $"{username}.private.key"));
|
||||
return File.ReadAllText(Path.Combine(GetKeyFolder(), $"{username}.private.key"));
|
||||
}
|
||||
|
||||
public static bool PrivateKeyExists(string username)
|
||||
public static string LoadPublicKey(string username)
|
||||
{
|
||||
return File.Exists(Path.Combine("keys", $"{username}.private.key"));
|
||||
return File.ReadAllText(Path.Combine(GetKeyFolder(), $"{username}.public.key"));
|
||||
}
|
||||
|
||||
public static bool HasKeys(string username)
|
||||
{
|
||||
return File.Exists(Path.Combine(GetKeyFolder(), $"{username}.private.key")) &&
|
||||
File.Exists(Path.Combine(GetKeyFolder(), $"{username}.public.key"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user