mirror of
https://github.com/opengram-server/opengram.git
synced 2026-09-14 22:44:17 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
namespace MyTelegram.AuthServer.Services;
|
||||
|
||||
public class RsaKeyProvider(IOptions<MyTelegramAuthServerOptions> options)
|
||||
: IRsaKeyProvider,
|
||||
ISingletonDependency
|
||||
{
|
||||
private string? _privateKey;
|
||||
|
||||
public string GetRsaPrivateKey()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_privateKey))
|
||||
{
|
||||
return _privateKey;
|
||||
}
|
||||
|
||||
if (!File.Exists(options.Value.PrivateKeyFilePath))
|
||||
{
|
||||
throw new FileNotFoundException(
|
||||
"Private key not exists",
|
||||
options.Value.PrivateKeyFilePath
|
||||
);
|
||||
}
|
||||
|
||||
_privateKey = File.ReadAllText(options.Value.PrivateKeyFilePath);
|
||||
|
||||
if (string.IsNullOrEmpty(_privateKey))
|
||||
{
|
||||
throw new InvalidOperationException("Private key can not be null");
|
||||
}
|
||||
|
||||
return _privateKey;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user