vapor / open-crypto

🔑 Hashing (BCrypt, SHA2, HMAC), encryption (AES), public-key (RSA), and random data generation.
MIT License
134 stars 34 forks source link

Error: AES256GCM.encrypt: expression type 'Data' is ambiguous without more context #76

Closed gentges closed 5 years ago

gentges commented 6 years ago

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)