Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sergeymakinen/go-crypt
crypt(3) hashes generator and validator
https://github.com/sergeymakinen/go-crypt
crypt crypto generator go golang hash validator
Last synced: 19 days ago
JSON representation
crypt(3) hashes generator and validator
- Host: GitHub
- URL: https://github.com/sergeymakinen/go-crypt
- Owner: sergeymakinen
- License: bsd-3-clause
- Created: 2021-06-16T18:51:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-01T18:38:17.000Z (11 months ago)
- Last Synced: 2024-10-16T22:53:41.310Z (about 1 month ago)
- Topics: crypt, crypto, generator, go, golang, hash, validator
- Language: Go
- Homepage:
- Size: 88.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# crypt
[![tests](https://github.com/sergeymakinen/go-crypt/workflows/tests/badge.svg)](https://github.com/sergeymakinen/go-crypt/actions?query=workflow%3Atests)
[![Go Reference](https://pkg.go.dev/badge/github.com/sergeymakinen/go-crypt.svg)](https://pkg.go.dev/github.com/sergeymakinen/go-crypt)
[![Go Report Card](https://goreportcard.com/badge/github.com/sergeymakinen/go-crypt)](https://goreportcard.com/report/github.com/sergeymakinen/go-crypt)
[![codecov](https://codecov.io/gh/sergeymakinen/go-crypt/branch/main/graph/badge.svg)](https://codecov.io/gh/sergeymakinen/go-crypt)Package crypt implements a basic interface to validate [crypt(3)](https://en.wikipedia.org/wiki/Crypt_(C)#Key_derivation_functions_supported_by_crypt) hashes.
Validation of any particular hash requires the prior registration of a check function.
Registration is typically automatic as a side effect of initializing that
hash's package so that, to validate an Argon2 has, it suffices to have```go
import _ "github.com/sergeymakinen/go-crypt/argon2"
```in a program's main package. The _ means to import a package purely for its
initialization side effects.## Supported hashing algorithms
Name
Package
Supported parameters
Example hash
- Salt
- Memory
- Time
- Threads
- Prefix (
$argon2d$
,$argon2i$
,$argon2id$
) - Version (1.0, 1.3)
$argon2id$v=19$m=512,t=3,p=1$qXMlAYBABLl$/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho
- Salt
- Cost
- Prefix (
$2$
,$2a$
,$2b$
)
$2b$10$UVjcf7m8L91VOpIRwEprguF4o9Inqj7aNhqvSzUElX4GWGyIkYLuG
- Salt
eNBO0nZMf3rWM
- Salt
- Rounds
_6C/.yaiu.qYIjNR7X.s
- Salt
$1$ip0xp41O$7DHwMihQRmDjn2tiJ17mw.
NT Hash
nthash
$3$$8846f7eaee8fb117ad06bdd830b7586c
- Salt
- Rounds
$sha1$48000$mHh0IIOQ$YS/Lw0PKCThSEBBYqP37zXySQ3cC
- Salt
- Rounds
$5$rounds=505000$.HnFpd3anFzRwVj5$EdcK/Q9wfmq1XsG5OTKP0Ns.ZlN9DRHslblcgCLtXY5
- Salt
- Rounds
$6$rounds=505000$69oRpYjidkp7hFdm$nbf4615NgTuG8kCnGYSjz/lXw4KrGMVR16cbCa9CSIHXK8UXwCK9bzCqDUw/I8hgb9Wstd1w5Bwgu5YG6Q.dm.
- Salt
- Rounds
- Prefix (
$md5,
,$md5$
) - Whether to add an empty value to a salt
$md5,rounds=5000$ReCRHeOH$$WOV3YlBRWykkmQDJc.uia/
## Custom hashes
It's also possible to implement a custom hash marshaling/unmarshaling via the hash package.
**Supported schemes**:
- DES: `()*`
- DES Extended (BSDi): `_()*`
- MCF/PHC: `$$fragment($)*`
Where:
- `` is `(|=|)`
- `` is `=,=(,=)*`
**Example**:
```go
var scheme = struct {
HashPrefix string
Cost string `hash:"length:2"`
Salt []byte `hash:"length:22,inline"`
Sum [31]byte
}
hash.Unmarshal("$2b$10$UVjcf7m8L91VOpIRwEprguF4o9Inqj7aNhqvSzUElX4GWGyIkYLuG", &scheme)
```
## Installation
Use go get:
```bash
go get github.com/sergeymakinen/go-crypt
```
Then import the package into your own code:
```go
import "github.com/sergeymakinen/go-crypt"
```
## Example
```go
package main
import (
"fmt"
"github.com/sergeymakinen/go-crypt"
_ "github.com/sergeymakinen/go-crypt/argon2"
_ "github.com/sergeymakinen/go-crypt/bcrypt"
)
var hashes = []string{
"$argon2id$v=19$m=512,t=3,p=1$qXMlAYBABLl$/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho", // Argon2
"$2b$12$mBhJFLLDJCBCcmMN4DLyrOV.LLSl/mdwGfzwsqvIL0OQN5yXzRihO", // bcrypt
"$unknown$foo", // Not registered
}
var passwords = []string{
"password",
"test",
}
func main() {
for _, hash := range hashes {
for _, password := range passwords {
fmt.Printf("%q with %q: %v\n", hash, password, crypt.Check(hash, password))
}
}
// Output:
// "$argon2id$v=19$m=512,t=3,p=1$qXMlAYBABLl$/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho" with "password":
// "$argon2id$v=19$m=512,t=3,p=1$qXMlAYBABLl$/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho" with "test": hash and password mismatch
// "$2b$12$mBhJFLLDJCBCcmMN4DLyrOV.LLSl/mdwGfzwsqvIL0OQN5yXzRihO" with "password":
// "$2b$12$mBhJFLLDJCBCcmMN4DLyrOV.LLSl/mdwGfzwsqvIL0OQN5yXzRihO" with "test": hash and password mismatch
// "$unknown$foo" with "password": unknown hash
// "$unknown$foo" with "test": unknown hash
}
```
## License
BSD 3-Clause