Paseto.Core
1.1.1
See the version list below for details.
dotnet add package Paseto.Core --version 1.1.1
NuGet\Install-Package Paseto.Core -Version 1.1.1
<PackageReference Include="Paseto.Core" Version="1.1.1" />
paket add Paseto.Core --version 1.1.1
#r "nuget: Paseto.Core, 1.1.1"
// Install Paseto.Core as a Cake Addin #addin nuget:?package=Paseto.Core&version=1.1.1 // Install Paseto.Core as a Cake Tool #tool nuget:?package=Paseto.Core&version=1.1.1
Paseto.NET, a Paseto (Platform-Agnostic Security Tokens) implementation for .NET
Features
PASETO protocols
purpose | v1 | v2 | v3 | v4 |
---|---|---|---|---|
local | ✅ | ✅ | ✅ | ✅ |
public | ✅ | ✅ | ✅ | ✅ |
PASERK extension
type | support |
---|---|
lid | ✅ |
local | ✅ |
seal | ❌ |
local-wrap | ❌ |
local-pw | ❌ |
sid | ✅ |
public | ✅ |
pid | ✅ |
secret | ✅ |
secret-wrap | ❌ |
secret-pw | ❌ |
Installation
Install the Paseto.Core NuGet package from the .NET CLI using:
dotnet add package Paseto.Core
or from the NuGet package manager:
Install-Package Paseto.Core
Usage
PASETO
The library exposes a Fluent API with several method overloads found in Use()
, WithKey()
, AddClaim()
, AddFooter()
and so on to provide the flexibility needed for encoding and decoding PASETO tokens and also for generating the required symmetric or asymmetric key pairs. However, you can use the Protocols and Handlers directly if you like.
Below are a couple of examples for the most common use cases:
Generating a crypto random Symmetric Key
var pasetoKey = new PasetoBuilder().Use(version, Purpose.Local)
.GenerateSymmetricKey();
Generating an Asymmetric Key Pair
var pasetoKey = new PasetoBuilder().Use(version, Purpose.Public)
.GenerateAsymmetricKeyPair(seed);
NOTE: A seed is not required for protocol v1.
Generating a Token
var token = new PasetoBuilder().Use(version, purpose)
.WithKey(key)
.AddClaim("data", "this is a secret message")
.Issuer("https://github.com/daviddesmet/paseto-dotnet")
.Subject(Guid.NewGuid().ToString())
.Audience("https://paseto.io")
.NotBefore(DateTime.UtcNow.AddMinutes(5))
.IssuedAt(DateTime.UtcNow)
.Expiration(DateTime.UtcNow.AddHours(1))
.TokenIdentifier("123456ABCD")
.AddFooter("arbitrary-string-that-isn't-json")
.Encode();
Decoding a Token
var result = new PasetoBuilder().Use(version, purpose)
.WithKey(key)
.Decode(token);
Or validate the token's payload while decoding (the header and signature is always validated):
var valParams = new PasetoTokenValidationParameters
{
ValidateLifetime = true,
ValidateAudience = true,
ValidateIssuer = true,
ValidAudience = "https://paseto.io",
ValidIssuer = "https://github.com/daviddesmet/paseto-dotnet"
};
var result = new PasetoBuilder().Use(version, purpose)
.WithKey(key)
.Decode(token, valParams);
PASERK
The library also provides the PASERK extension for encoding and decoding a key.
A serialized key in PASERK has the format:
k[version].[type].[data]
Encoding a Key
var paserk = Paserk.Encode(pasetoKey, type);
Decoding a Key
var key = Paserk.Decode(paserk);
Roadmap
- Add support for remaining PASERK types and its operations.
- Add support for version detection when decoding.
- Add support for custom payload validation rules.
- Improve documentation.
- Remove dependency on JSON.NET.
Test Coverage
- Includes the mandatory test vectors for PASETO and PASERK.
Cryptography
- Uses Ed25519 (EdDSA over Curve25519) algorithm from CodesInChaos Chaos.NaCl cryptography library.
- Uses Blake2b cryptographic hash function from Konscious.Security.Cryptography repository.
- Uses AES-256-CTR, ECDSA over P-384 algorithms from Bouncy Castle cryptography library.
- Uses XChaCha20-Poly1305 AEAD from NaCl.Core repository.
Learn More
- PASETO (Platform-Agnostic SEcurity TOkens) is a specification and reference implementation for secure stateless tokens.
- PASERK (Platform-Agnostic SERialized Keys) is an extension to PASETO that provides key-wrapping and serialization.
Product | Versions 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 is compatible. 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. |
-
net6.0
- NaCl.Core (>= 2.0.5)
- Newtonsoft.Json (>= 13.0.3)
- Portable.BouncyCastle (>= 1.9.0)
-
net8.0
- NaCl.Core (>= 2.0.5)
- Newtonsoft.Json (>= 13.0.3)
- Portable.BouncyCastle (>= 1.9.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Paseto.Core:
Package | Downloads |
---|---|
PasetoBearer.Authentication
A simple implementation for securing the API by public PASETO access tokens. |
|
FAPIServer
Core logic for FAPI Server |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.3.0 | 1,275 | 7/15/2024 |
1.2.1 | 940 | 6/23/2024 |
1.1.1 | 3,089 | 5/16/2024 |
1.1.0 | 24,900 | 4/20/2023 |
1.0.7 | 68,966 | 8/24/2022 |
1.0.6 | 18,626 | 5/24/2022 |
1.0.5 | 142 | 5/11/2022 |
1.0.4 | 2,488 | 4/28/2022 |
1.0.3 | 217 | 4/16/2022 |
0.7.2 | 81,977 | 7/9/2019 |
0.7.1 | 812 | 2/5/2019 |
0.7.0 | 2,255 | 11/27/2018 |
0.6.1 | 1,255 | 4/6/2018 |
0.6.0 | 1,030 | 3/30/2018 |
0.5.5 | 1,114 | 3/20/2018 |
0.5.4 | 939 | 3/19/2018 |
0.5.3 | 936 | 3/16/2018 |