项目作者: laget-se

项目描述 :
Default implementation of Secure Pre-Shared Key (PSK) Authentication for laget.se using Rijndael.
高级语言: C#
项目地址: git://github.com/laget-se/laget.PskAuthentication.git
创建时间: 2020-12-08T12:00:04Z
项目社区:https://github.com/laget-se/laget.PskAuthentication

开源协议:Apache License 2.0

下载


laget.PskAuthentication

Generic implementation of Secure Pre-Shared Key (PSK) Authentication for laget.se using AES.

Nuget
Nuget

Nuget
Nuget

Nuget
Nuget

Configuration

This example is shown using Autofac since this is the go-to IoC for us.
```c#
public class OptionModule : Module
{
readonly IConfiguration _configuration;

  1. public OptionModule(IConfiguration configuration)
  2. {
  3. _configuration = configuration;
  4. }
  5. protected override void Load(ContainerBuilder builder)
  6. {
  7. builder.Register(c => new PskAuthenticationAttribute(new PskAuthenticationOptions
  8. {
  9. Key = _configuration.GetValue<string>("Security:Key"),
  10. IV = _configuration.GetValue<string>("Security:IV"),
  11. Salt = _configuration.GetValue<string>("Security:Salt"),
  12. Secret = _configuration.GetValue<string>("Security:Secret")
  13. })).AsSelf();
  14. }

}

  1. ### appsettings.json
  2. ```c#
  3. "Security": {
  4. "Key": "...",
  5. "IV": "...",
  6. "Salt": "...",
  7. "Secret": "..."
  8. }

Usage

Controller

  1. [PskAuthentication]
  2. public class SomeController : ControllerBase
  3. {
  4. }

Aes

You can generate the necessary Aes properties via the code below or visit https://rextester.com/RMKPPK46300

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Security.Cryptography;
  6. namespace Rextester
  7. {
  8. public class Program
  9. {
  10. public static void Main(string[] args)
  11. {
  12. var aes = Aes.Create();
  13. aes.Mode = CipherMode.CBC;
  14. aes.Padding = PaddingMode.PKCS7;
  15. aes.GenerateIV();
  16. aes.GenerateKey();
  17. Console.WriteLine(Convert.ToBase64String(aes.IV));
  18. Console.WriteLine(Convert.ToBase64String(aes.Key));
  19. }
  20. }
  21. }