|
1 |
| -# Cryptipass |
2 |
| -NOTE: **We also have a [CLI](cmd/genpw) available for non-library uses.** |
3 |
| -Cryptipass is a Go package designed to generate secure passphrases composed of human-readable words. The passphrases are generated with a focus on both security (through entropy) and usability by combining cryptographic randomness and customizable word generation strategies. |
| 1 | +# cryptipass |
| 2 | + |
| 3 | +[](https://goreportcard.com/report/github.com/francescoalemanno/cryptipass) |
| 4 | +[](https://opensource.org/licenses/MIT) |
| 5 | +[](https://pkg.go.dev/github.com/francescoalemanno/cryptipass) |
| 6 | + |
| 7 | +**cryptipass** is a flexible, high-entropy passphrase generator that creates secure, pronounceable passwords using a probabilistic model. It's designed for security-conscious developers who need memorable yet strong passphrases. |
| 8 | + |
| 9 | +--- |
4 | 10 |
|
5 | 11 | ## Features
|
6 | 12 |
|
7 |
| -- **Cryptographically secure randomization**: Uses `crypto/rand` for generating random data to seed the passphrase generation process, ensuring the highest level of security. |
8 |
| -- **Customizable passphrase length**: The number of words in the passphrase can be controlled by the user. |
9 |
| -- **Entropy calculation**: Provides an exact evaluation of the total entropy for the generated passphrase, helping users understand the strength of their passphrase. |
10 |
| -- **Configurable word lengths**: Words within the passphrase can vary in length, ensuring better randomness and complexity. |
| 13 | +- **Pronounceable Passwords**: Generates words based on real-world token patterns, making them easy to remember. |
| 14 | +- **Highly Customizable**: Define your own word list or use pre-defined patterns like symbols, numbers, and mixed-case letters. |
| 15 | +- **Secure Randomness**: Uses cryptographic-grade randomness (`crypto/rand`) for generating passphrases. |
| 16 | +- **Entropy Analysis**: Built-in entropy calculations and certification to ensure high randomness and strength. |
| 17 | +- **Pattern-Based Generation**: Control password structure using customizable patterns (e.g., words, digits, symbols). |
| 18 | + |
| 19 | +--- |
11 | 20 |
|
12 | 21 | ## Installation
|
13 | 22 |
|
14 |
| -To use the `cryptipass` package in your project, you need to install it using Go's package management: |
| 23 | +To install `cryptipass`, use `go get`: |
15 | 24 |
|
16 | 25 | ```bash
|
17 | 26 | go get github.com/francescoalemanno/cryptipass
|
18 | 27 | ```
|
19 | 28 |
|
20 |
| -Then import it in your Go files: |
| 29 | +Then, import it into your project: |
21 | 30 |
|
22 | 31 | ```go
|
23 | 32 | import "github.com/francescoalemanno/cryptipass"
|
24 | 33 | ```
|
25 | 34 |
|
26 |
| -## Usage |
| 35 | +NOTE: **We also have a [CLI](cmd/genpw) available for non-library uses.** |
27 | 36 |
|
28 |
| -### Generate a Passphrase |
| 37 | +--- |
29 | 38 |
|
30 |
| -The primary function of the `cryptipass` package is to generate secure passphrases. You can generate a new passphrase using the `NewPassphrase` function. You can specify how many words you want in the passphrase, and the function returns the passphrase and its total entropy. |
| 39 | +## Quick Start |
31 | 40 |
|
32 |
| -Example: |
| 41 | +Here's how to generate a passphrase using the default word style: |
33 | 42 |
|
34 | 43 | ```go
|
35 | 44 | package main
|
36 | 45 |
|
37 | 46 | import (
|
38 | 47 | "fmt"
|
39 |
| - "cryptipass" |
| 48 | + "github.com/francescoalemanno/cryptipass" |
40 | 49 | )
|
41 | 50 |
|
42 | 51 | func main() {
|
43 |
| - passphrase, entropy := cryptipass.NewPassphrase(5) |
44 |
| - fmt.Printf("Passphrase: %s\n", passphrase) |
45 |
| - fmt.Printf("Entropy: %.2f bits\n", entropy) |
| 52 | + // Create a new cryptipass generator |
| 53 | + gen := cryptipass.NewInstance() |
| 54 | + |
| 55 | + // Generate a 4-word passphrase |
| 56 | + passphrase, entropy := gen.GenPassphrase(4) |
| 57 | + |
| 58 | + fmt.Println("Passphrase:", passphrase) //e.g. netica.peroundl.opantmene.symnals |
| 59 | + fmt.Println("Entropy:", entropy) |
46 | 60 | }
|
47 | 61 | ```
|
48 | 62 |
|
49 |
| -### Example Output: |
| 63 | +Want more control over the pattern? Use `GenFromPattern`: |
50 | 64 |
|
| 65 | +```go |
| 66 | +// Generate a password with pattern: Word-Number-Symbol |
| 67 | +pass, entropy := gen.GenFromPattern("w-d-s") // eg. opantmene-4-% |
| 68 | +fmt.Println("Generated Password:", pass) |
51 | 69 | ```
|
52 |
| -Passphrase: jesside.flyperm.aunsis.dertsy |
53 |
| -Entropy: 97.63 bits |
54 |
| -``` |
55 | 70 |
|
56 |
| -### Word Generation |
| 71 | +Possible patterns are formed by combining: |
| 72 | +- 'w' lowercase word, 'W' for uppercase word. |
| 73 | +- 'c' a lowercase character, 'C' a uppercase character. |
| 74 | +- 's' symbol, 'd' digit. |
| 75 | + |
| 76 | +other symbols are interpolated in the final password and to interpolate one of the reserved symbols use escaping with "\". |
| 77 | + |
| 78 | +--- |
57 | 79 |
|
58 |
| -Internally, the package uses a series of functions to generate words of varying lengths. Each word contributes a certain amount of entropy, calculated during the generation process. |
| 80 | +## Custom Word Lists |
59 | 81 |
|
60 |
| -- `GenMixWord()`: Generates a random word of mixed length, returning both the word and its entropy. |
61 |
| -- `GenWord(n int)`: Generates a word of exactly `n` characters. |
62 |
| -- `PickLength()`: Picks a random length for a word. |
63 |
| -- `PickNext()`: Generates the next part of a word based on the current string. |
| 82 | +You can customize the word style by creating a new instance from your own token set: |
64 | 83 |
|
65 |
| -## Notes |
| 84 | +```go |
| 85 | +myTokens := []string{"alpha", "bravo", "charlie", "delta"} |
| 86 | +gen := cryptipass.NewCustomInstance(myTokens, 1) //instead of 1, try 2,3,4 to see the tradeoff between fidelity to the wordlist and entropy gain. |
66 | 87 |
|
67 |
| -- The package seeds the random number generator with `crypto/rand`, making it cryptographically secure. In scenarios where cryptographic security is not necessary and faster execution is preferred, the package also provides an alternative (commented out) `PCG` random number generator. |
68 |
| -- The entropy provided in the output is a measure of how unpredictable the passphrase is. The higher the entropy, the more secure the passphrase is. |
| 88 | +pass, entropy := gen.GenPassphrase(3) |
| 89 | +fmt.Println("Custom Passphrase:", pass) //e.g. alphar.bravo.delta |
| 90 | +fmt.Println("Entropy:", entropy) |
| 91 | +``` |
69 | 92 |
|
70 |
| -## Contributing |
| 93 | +--- |
| 94 | + |
| 95 | +## Documentation |
71 | 96 |
|
72 |
| -Contributions are welcome! If you encounter any issues or have feature suggestions, feel free to open an issue or a pull request on the GitHub repository. |
| 97 | +Full API documentation is available at [GoDoc](https://pkg.go.dev/github.com/francescoalemanno/cryptipass). |
| 98 | + |
| 99 | +--- |
73 | 100 |
|
74 | 101 | ## License
|
75 | 102 |
|
76 |
| -This project is licensed under the MIT License. |
| 103 | +`cryptipass` is licensed under the MIT License. See [LICENSE](LICENSE) for details. |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## Contributing |
| 108 | + |
| 109 | +Contributions, issues, and feature requests are welcome! Feel free to check out [issues](https://github.com/francescoalemanno/cryptipass/issues) or open a pull request. |
77 | 110 |
|
78 | 111 | ---
|
79 | 112 |
|
80 |
| -Happy coding and stay secure with Cryptipass! |
| 113 | +**cryptipass** – Secure, flexible, and pronounceable passphrases for your Go applications. |
0 commit comments