https://github.com/prongbang/gojwe
JWE (AES/GCM A256GCM, ChaCha20-Poly1305, XChaCha20-Poly1305) wrapper for Golang.
https://github.com/prongbang/gojwe
aes-gcm256 chacha20-poly1305 gojwe jwe jwe-aes-gcm-256 jwe-chacha20-poly1305 jwe-xchacha20-poly1305 xchacha20-poly1305
Last synced: 6 months ago
JSON representation
JWE (AES/GCM A256GCM, ChaCha20-Poly1305, XChaCha20-Poly1305) wrapper for Golang.
- Host: GitHub
- URL: https://github.com/prongbang/gojwe
- Owner: prongbang
- License: mit
- Created: 2024-03-09T11:52:37.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-09T10:37:37.000Z (8 months ago)
- Last Synced: 2025-03-25T22:52:07.444Z (6 months ago)
- Topics: aes-gcm256, chacha20-poly1305, gojwe, jwe, jwe-aes-gcm-256, jwe-chacha20-poly1305, jwe-xchacha20-poly1305, xchacha20-poly1305
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gojwe
JWE (AES/GCM A256GCM, ChaCha20-Poly1305, XChaCha20-Poly1305) wrapper for Golang.
## Install
```shell
go get github.com/prongbang/gojwe
```## How to use
- Random Secret Key
```shell
openssl rand -hex 32
```- Benchmark AES GCM-256
```shell
cpu: Apple M4 Pro
BenchmarkAesGcm256Generate-12 184796 5714 ns/op
BenchmarkAesGcm256Parse-12 197023 6048 ns/op
BenchmarkAesGcm256Verify-12 198123 6033 ns/op
```- Benchmark ChaCha20-Poly1305
```shell
cpu: Apple M4 Pro
BenchmarkChaCha20Generate-12 1000000 1124 ns/op
BenchmarkChaCha20Parse-12 1000000 1018 ns/op
BenchmarkChaCha20Verify-12 1000000 1004 ns/op
```- Benchmark XChaCha20-Poly1305
```shell
cpu: Apple M4 Pro
BenchmarkXChaCha20Generate-12 996456 1211 ns/op
BenchmarkXChaCha20Parse-12 1000000 1085 ns/op
BenchmarkXChaCha20Verify-12 1000000 1087 ns/op
```- New instance AES GCM-256
```go
j := gojwe.New(gojwe.AESGCM256)
```- New instance ChaCha20-Poly1305
```go
j := gojwe.New(gojwe.ChaCha20)
```- New instance XChaCha20-Poly1305
```go
j := gojwe.New(gojwe.XChaCha20)
```- Generate
```go
key, _ := hex.DecodeString("bdacaf398071931518f73917cb0c6f04b3a0ab45ee9cbedc258047a8c149a3e1")payload := map[string]any{
"exp": 99999999999,
}
accessToken, err := j.Generate(payload, key)
```- Parse
```go
key, _ := hex.DecodeString("bdacaf398071931518f73917cb0c6f04b3a0ab45ee9cbedc258047a8c149a3e1")accessToken := "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjk5OTk5OTk5OTk5fQ.rMKkGe6riuLZ3boYiMZsk5xrT7S-7VK6gZmFs1_7kKtVUkpvGatudYI5ZSkwIQ-iJKp2XskCxzn_6fVkCohtUQ"
payload, err := j.Parse(accessToken, key)
```- Verify
```go
key, _ := hex.DecodeString("bdacaf398071931518f73917cb0c6f04b3a0ab45ee9cbedc258047a8c149a3e1")accessToken := "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjk5OTk5OTk5OTk5fQ.rMKkGe6riuLZ3boYiMZsk5xrT7S-7VK6gZmFs1_7kKtVUkpvGatudYI5ZSkwIQ-iJKp2XskCxzn_6fVkCohtUQ"
valid := j.Verify(accessToken, key)
```