Giter VIP home page Giter VIP logo

dk's Introduction

Golang Derived Key Generator helper library

Library to take 2 inputs (lock and key) to produce a derived key using argon2id. Useful to generate master keys and its hash signature for various use cases, such as encryption/decryption keys.

Both the lock and key will be used to generate the salt and the input for argon2id will be HMAC.

Only the signature of the key will be stored in databases or such, the actual key never touches any datastore. This allows it to be used and discarded as needed.

Using this library

lock := []byte("[email protected]")
key := []byte("hello, world!")

d, err := dk.New(lock, key)
if nil != err {
    fmt.Println(err)
    os.Exit(1)
}
fmt.Println(d.Key)
fmt.Println(d.Sig)

// the signature will come from a remote database or such
s, err := hex.DecodeString(d.Sig.String())
if nil != err {
    fmt.Println(err)
    os.Exit(1)
}

fmt.Println(d.Match(s))

How it works

Assume the lock is the email, and key is the password.

  1. Create a new instance of blake2b with no input key for the salt.
  2. Write the bytes of lock into this blake2b instance.
  3. Write the bytes of key into this blake2b instance.
  4. Take the first 16 bytes of this result as salt.
  5. Create new hmac instance using sha3-384 and key as the key.
  6. Write the bytes of lock into this hmac instance.
  7. The result of this will be the input to be fed into argon2id.
  8. Create new argon2id instance with the following parameters a. memory = 64MB (64 * 1024) b. iterations = 3 c. parallelism = 4 d. saltLength = 16 e. keyLength = 32
  9. Set the salt of argon2id with the value from step (4).
  10. Using the value from step (7), generate the key using argon2id.
  11. The signature of this key is a sha3-256 which can be stored in a database or such.

dk's People

Watchers

Vicknesh Suppramaniam avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.