Encrypt [String:Any] with curve25519

183 Views Asked by At

i want to encrypt the Data I upload to Firebase with curve25519.

Atm i convert my custom model to [String: Any] and upload this to firebase firestore. Now I want to encrypt the Data. I thought that I understand how the public/privat key stuff works, but when I search for guides, they always (if I understand it right) use the privat key to encrypt (signature) the Data and the public key to decrypt (isValidSignature) the data.

I don't understand this. I thought that u need the public key to encrypt the data, so the receiver have to use the privat key to decrypt the data and read it.

The Code that others used to encrypt my Dic I found so far looks like this:

 let jsonData = try? JSONSerialization.data(withJSONObject: Dic)
 
 let digest512 = SHA512.hash(data: jsonData!)
 
 let signatureForDigest = try! PrivateKey.signature(for: Data(digest512))

But I don't understand where the public key comes into the code. How I use the public key so the receiver can decrypt it with his privat key?

Hope someone can help me. Im really stuck and cant find anything that helps me. I only get more confused.

Greets

0

There are 0 best solutions below