Hello,
I am having a problem right now and don't know how to solve it.
I wrote a controller for managing my users. The following code is an excerpt from my registration function, where a key is generated for encrypting user data that is later stored in the database. The key (ekey) is stored in the database, too. So I need to enctrypt the key and therefore I use a hash of the users password.
I'm getting the error on the last line, but I don't know what is wrong with that.
// generate key for encrypting data
let ekey = try URandom().generateData(count: 32).base64EncodedString()
// generate digest for password and encrypt 'ekey'
let key: Data = try SHA256.hash(user.password)
let iv: Data = try URandom().generateData(count: 12)
let (encrKey, tag) = try AES256GCM.encrypt(ekey, key: key, iv: iv)
Hello, I am having a problem right now and don't know how to solve it. I wrote a controller for managing my users. The following code is an excerpt from my registration function, where a key is generated for encrypting user data that is later stored in the database. The key (
ekey
) is stored in the database, too. So I need to enctrypt the key and therefore I use a hash of the users password. I'm getting the error on the last line, but I don't know what is wrong with that.