Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "crypto/sha1"
  5. "crypto/sha256"
  6. "fmt"
  7.  
  8. "github.com/howeyc/gopass"
  9. "golang.org/x/crypto/pbkdf2"
  10. )
  11.  
  12. func main() {
  13. fmt.Printf("%s\n\n", " >>> Supply Password to generate a secure Key")
  14.  
  15. // get password from the user terminal
  16. // password is in bytes
  17. password, err := gopass.GetPasswdMasked()
  18. if err != nil {
  19. fmt.Println("error reading password")
  20. return
  21. }
  22.  
  23. // we need to add salt to make our
  24. // derived key stronger to crack
  25. salt := []byte("mysaltedSalt")
  26.  
  27. // print out the original password entered by the user
  28. fmt.Printf("1.) Original Password :-> %s\n\n", string(password))
  29.  
  30. // hash the original password
  31. // using sha-1
  32. hashedPassword := sha256.Sum256([]byte(password))
  33.  
  34. fmt.Printf("2.) Hashed Password :-> %x\n\n", hashedPassword)
  35.  
  36. // generate the derived key
  37. // base on the input parameter
  38. // password to stretch
  39. // salt to use
  40. // number of iteration to use while generating the new key
  41. // length of the new key to be generated
  42. // hash function to be used while deriving the new key
  43. derivedKey := pbkdf2.Key(password, salt, 10, 128, sha1.New)
  44.  
  45. // print out the derived key
  46. fmt.Printf("3.) KDF Key :-> %x\n\n", derivedKey)
  47.  
  48. // compute the hash function of the derived key to make it stronger
  49. hashDerviedKey := sha256.Sum256(derivedKey)
  50.  
  51. // print the hash of the derived key
  52. fmt.Printf("4.) Hashed Derived Key :-> %x\n\n", hashDerviedKey)
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement