https://github.com/prongbang/lazyaesgcm
Lazy AES-GCM in Golang
https://github.com/prongbang/lazyaesgcm
aes-gcm aes-gcm-256 lazyaesgcm
Last synced: about 1 month ago
JSON representation
Lazy AES-GCM in Golang
- Host: GitHub
- URL: https://github.com/prongbang/lazyaesgcm
- Owner: prongbang
- License: mit
- Created: 2024-04-19T09:17:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-19T09:54:40.000Z (over 1 year ago)
- Last Synced: 2025-03-25T22:52:05.990Z (8 months ago)
- Topics: aes-gcm, aes-gcm-256, lazyaesgcm
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lazyaesgcm
Lazy AES-GCM in golang on [golang.org/x/crypto](golang.org/x/crypto).
[](https://goreportcard.com/report/github.com/prongbang/lazyaesgcm)
[](https://www.buymeacoffee.com/prongbang)
### Algorithm details
- Key exchange: X25519
- Encryption: AES
- Authentication: GCM
### Install
```
go get github.com/prongbang/lazyaesgcm
```
### Benchmark
```shell
BenchmarkEncrypt-10 876500 1352 ns/op 1728 B/op 9 allocs/op
BenchmarkDecrypt-10 1317686 865.9 ns/op 1408 B/op 8 allocs/op
```
### How to use
- Generate KeyPair
```go
keyPair := lazyaesgcm.NewKeyPair()
```
- Key Exchange
```go
clientKp := lazyaesgcm.NewKeyPair()
serverKp := lazyaesgcm.NewKeyPair()
serverKx := serverKp.Exchange(clientKp.Pk)
clientKx := clientKp.Exchange(serverKp.Pk)
```
- Shared Key
```go
serverSharedKey, _ := serverKx.Secret()
clientSharedKey, _ := clientKx.Secret()
```
- Encrypt
```go
lazyAesGcm := lazyaesgcm.New()
sharedKey, _ := clientKx.Secret()
key, _ := hex.DecodeString(sharedKey)
plaintext := "text"
ciphertext, err := lazyAesGcm.Encrypt(plaintext, key)
```
- Decrypt
```go
lazyAesGcm := lazyaesgcm.New()
sharedKey, _ := serverKx.Secret()
key, _ := hex.DecodeString(sharedKey)
ciphertext := "f6a1bd8"
plaintext, err := lazyAesGcm.Decrypt(ciphertext, key)
```