Hash password with another password

50 Views Asked by At

I want to understand what is the best option to hash password with a different password.

What I mean by that - let's take standard encryption as an example:

package password

import "golang.org/x/crypto/bcrypt"

func Hash(password string) (string, error) {
    bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
    return string(bytes), err
}

func Verify(hashed, password string) bool {
    err := bcrypt.CompareHashAndPassword([]byte(hashed), []byte(password))
    return err == nil
}

Here I can generate a hash from the same password that I use to encrypt.

But what if for instance, I store other passwords like to my email configuration, payment details, etc?

How do I encrypt it in Golang with let's say this .env stored key 454ec400-2d9d-422d-940e-39eb2be0812e?

0

There are 0 best solutions below