Skip to content

keygen is a lightweight library, which implements a faster unique key generator.

License

Notifications You must be signed in to change notification settings

barbosaigor/keygen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keygen

Keygen is a lightweight library, which implements a faster unique key generator. It is possible to change the symbols used to generate the key, as well as the key size. This library is not recommended for security algorithms, but is well suitable for
applications that need a faster key generator. For better performance there is the cache package, which implements an in-memory cache containing a set of unique keys.

Installation

go get github.com/barbosaigor/keygen

Usage

Next generates a new key and returns it. The key is generated such as a sum of two numbers, though it will be using the current symbols.

// Creates a key generator that generates a 7 length key  
// 'New' will use base 64 symbols for the key
kgen := keygen.New(7)  
// Next generates a new 7 length key  
key := kgen.Next()  

Keys generates a set of N unique keys.

// Creates a key generator that generates a 13 length key  
kgen := keygen.New(13)  
keys := kgen.Keys(2000)

NewWithCustomSymbols creates a Key generator that is going to use a set of symbols to generate the keys. If the symbols is not provided then it will use base 64 characters such as 'New'.

symbols := []rune{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
kgen := keygen.NewWithCustomSymbols(symbols, 5)
keys := key.Keys(2000)

Cache

Key returns a key from the cache. Before returning a key, if the cache is empty then it is going to calculate new keys as well.

symbols := []rune{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
keySize := 5
cacheCapacity := 5000
// If the symbols are not provided (nil), then cache will use base 64 symbols instead.  
kgenCache := cache.New(symbols, keySize, cacheCapacity)
key := kgenCache.Key()

About

keygen is a lightweight library, which implements a faster unique key generator.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages