INNER CODE UNIT · Go
decryptWithPassword
volodymyrprokopyuk/go-blockchain · chain/account.go:176
func decryptWithPassword(ciph, pass []byte) ([]byte, error) {
salt, ciph := ciph[:encKeyLen], ciph[encKeyLen:]
key := argon2.IDKey(pass, salt, 1, 256, 1, encKeyLen)
blk, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
gcm, err := cipher.NewGCM(blk)
if err != nil {
return nil, err
}
nonceLen := gcm.NonceSize()
nonce, ciph := ciph[:nonceLen], ciph[nonceLen:]
msg, err := gcm.Open(nil, nonce, ciph, nil)
if err != nil {
return nil, err
}
return msg, nil