NETSigner.AspNetCore 1.0.2

dotnet add package NETSigner.AspNetCore --version 1.0.2                
NuGet\Install-Package NETSigner.AspNetCore -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NETSigner.AspNetCore" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NETSigner.AspNetCore --version 1.0.2                
#r "nuget: NETSigner.AspNetCore, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NETSigner.AspNetCore as a Cake Addin
#addin nuget:?package=NETSigner.AspNetCore&version=1.0.2

// Install NETSigner.AspNetCore as a Cake Tool
#tool nuget:?package=NETSigner.AspNetCore&version=1.0.2                

NETSigner

提供 API 签名验证功能,遵循 使用摘要签名认证方式调用 API 签名规范

简单使用

asp.netcore

安装

在项目目录下执行下列命令

dotnet add package NETSigner
dotnet add package NETSigner.AspNetCore

代码

///Program.cs

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddNETSigner();

var app = builder.Build();

app.UseNETSigner();

app.Map("sign", context => context.Response.WriteAsync("> success"));

await app.RunAsync();

高级

自定义 SKGetter

由于在传输过程中 sk 容易暴露,所以需要我们引入了 ak,服务端通过 ak 来指向一个 sk。这样就可以不用暴露 sk

///MySKGetter.cs

public class MySKGetter : ISKGetter
{

    public string GetSK(string ak)
    {
        //访问数据库获取sk并return
        return "sk";
    };
}
///Program.cs
...
builder.Services.AddSingleton<ISKGetter, MySKGetter>();
builder.Services.AddNETSigner();
...

自定义 NonceRecorder

为了防止请求重放攻击,我们引入了 nonce

///MyNonceRecorder.cs

public class MyNonceRecorder : INonceRecorder
{
    private readonly ConcurrentDictionary<string, byte> _cache = new();

    public bool Record(string nonce, TimeSpan delay)
    {
        //加入到缓存,并设置过期时间。(我这里的代码只是示例,具体如何实现加入redis缓存需要自行研究)
        return _cache.TryAdd(nonce, 0);
    }
}
///Program.cs
...
builder.Services.AddSingleton<INonceRecorder, MyNonceRecorder>();
builder.Services.AddNETSigner();
...
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 481 3/24/2022
1.0.0 422 3/2/2022