Skip to content

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

License

Notifications You must be signed in to change notification settings

laget-se/laget.PskAuthentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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<string>("Security:Key"),
            IV = _configuration.GetValue<string>("Security:IV"),
            Salt = _configuration.GetValue<string>("Security:Salt"),
            Secret = _configuration.GetValue<string>("Security:Secret")
        })).AsSelf();
    }
}

appsettings.json

"Security": {
  "Key": "...",
  "IV": "...",
  "Salt": "...",
  "Secret": "..."
}

Usage

Controller

[PskAuthentication]
public class SomeController : ControllerBase
{
}

Aes

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

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));
        }
    }
}

About

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

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages