Posts

Post marked as solved
7 Replies
2.6k Views
Hi, How do I generate the pem representation of a curve25519 public key? I can generate the key using :      let privateKey = Curve25519.KeyAgreement.PrivateKey() let publicKey = privateKey.publicKey print(publicKey.rawRepresentation.base64EncodedString()) This prints a string like this : GyQfzi3bLfpDpzi8e9j6lovX15EZY1t1fQQcnJlURxI= But the expected strings are more like : ----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEApxUNh3jHlNSAWE7fadipsh9AjXv6439VY3EWEC5kbgY=\n-----END PUBLIC KEY Even if I add the " -----BEGIN PUBLIC KEY-----" and "-----END PUBLIC KEY-----" tags, it still doesn't process the key. So what format is exactly the base64 encoded string of the raw format of curve25519 public key? And how do I generate the public key pem format? The requirement is for Swift iOS.
Posted Last updated
.
Post marked as solved
11 Replies
3.2k Views
Hi, I'm using Curve25519 to generate the public-private key pair that's to be used for creating the shared Secret. The public key received from the server is but a very long message(base64 encoded string), which is about 309 bytes when converted to Data. When I try to create the shared secret key using this data, CryptoKit throws the error "CryptoKit.CryptoKitError.incorrectKeySize" at this line: swift      let serverPublicKey = try! Curve25519.KeyAgreement.PublicKey(rawRepresentation: serverPublicKeyData) I need the output of this line(serverPublicKey) for generating the shared secret. Here's the rest of the code: swift      let clientPrivateKey = Curve25519.KeyAgreement.PrivateKey()      let clientSharedSecret = try! clientPrivateKey.sharedSecretFromKeyAgreement(with: serverPublicKey)      let clientSharedSecretyKey = clientSharedSecret.x963DerivedSymmetricKey(using: SHA256.self, sharedInfo: Data(), outputByteCount: 32) and I'm encrypting using AES.GCM swift      let clientSealedBoxData = try! AES.GCM.seal(messageData, using: clientSharedSecretyKey).combined!      let clientSealedBox = try! AES.GCM.SealedBox(combined: clientSealedBoxData) where messageData is the data to be encrypted Is there any way to compress the received public key to 32 bytes to pass it to the KeyAgreement line? (Also, is this the right method to generate the public key for encrypting?) I've referred a lot of sites but couldn't arrive at a solution. Please help.
Posted Last updated
.