1

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

Mobias
  • 31
  • 3
  • 1
    You cannot directly encrypt with Curve25519. It can be used for signing and for key agreement. If you use it for key agreement, then you can (symmetrically) encrypt using the agreed key. A signature is not encryption. – Rob Napier Jul 15 '21 at 20:35

0 Answers0