Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/laget-se/laget.pskauthentication
Generic implementation of Secure Pre-Shared Key (PSK) Authentication for laget.se using AES.
https://github.com/laget-se/laget.pskauthentication
aes-encryption authentication nuget psk
Last synced: 19 days ago
JSON representation
Generic implementation of Secure Pre-Shared Key (PSK) Authentication for laget.se using AES.
- Host: GitHub
- URL: https://github.com/laget-se/laget.pskauthentication
- Owner: laget-se
- License: apache-2.0
- Created: 2020-12-08T12:00:04.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-30T20:41:25.000Z (4 months ago)
- Last Synced: 2024-12-04T12:15:07.949Z (3 months ago)
- Topics: aes-encryption, authentication, nuget, psk
- Language: C#
- Homepage:
- Size: 147 KB
- Stars: 0
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# laget.PskAuthentication
Generic implementation of Secure Pre-Shared Key (PSK) Authentication for laget.se using AES.


## Configuration
> This example is shown using Autofac since this is the go-to IoC for us.
```c#
public class OptionModule : Module
{
readonly IConfiguration _configuration;public OptionModule(IConfiguration configuration)
{
_configuration = configuration;
}protected override void Load(ContainerBuilder builder)
{
builder.Register(c => new PskAuthenticationAttribute(new PskAuthenticationOptions
{
Key = _configuration.GetValue("Security:Key"),
IV = _configuration.GetValue("Security:IV"),
Salt = _configuration.GetValue("Security:Salt"),
Secret = _configuration.GetValue("Security:Secret")
})).AsSelf();
}
}
```### appsettings.json
```c#
"Security": {
"Key": "...",
"IV": "...",
"Salt": "...",
"Secret": "..."
}
```## Usage
### Controller
```c#
[PskAuthentication]
public class SomeController : ControllerBase
{
}
```## Aes
You can generate the necessary Aes properties via the code below or visit https://rextester.com/RMKPPK46300```c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
var aes = Aes.Create();
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
aes.GenerateIV();
aes.GenerateKey();
Console.WriteLine(Convert.ToBase64String(aes.IV));
Console.WriteLine(Convert.ToBase64String(aes.Key));
}
}
}
```