Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with CC.EC.computeSharedSecret #58

Open
NikSrg opened this issue Jan 31, 2020 · 0 comments
Open

Problem with CC.EC.computeSharedSecret #58

NikSrg opened this issue Jan 31, 2020 · 0 comments

Comments

@NikSrg
Copy link

NikSrg commented Jan 31, 2020

Hi @soyersoyer, first of all: great work, I really appreciate!
So happy to find you repo, I was wasting endless hours till I found you :)

My problem is getting the shared secret for a elliptic curve - diffie-hellman - key agreement
I have the public key from a server

let serverPublicKeyString = """
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzgg42Iyyx+DZs4vql5tb/zmrF0zFnnfXOsBvmr+Q7MjXViCAiwgaxrNpGn3pN5f67qY3r7p+qUO6sVakjT82cg==
-----END PUBLIC KEY-----
"""

I created my own key pair in the app using:
let clientKeys = try! CC.EC.generateKeyPair(256)

I created a data object from the server public key string:
let serverKeyData = try! SwKeyConvert.PublicKey.pemToPKCS8DER(serverPublicKeyString)

But I can't figure why I don't get a shared secret through
let shared = try? CC.EC.computeSharedSecret(clientKeys.0, publicKey: serverKeyData)
Error: [generateKeyPair(_:)] SwCrypt.CC.CCError: paramError (-4300)

What I know about the server public key:

  • Created in Java ECGenParameterSpec("secp256r1")
  • Exported as base64. I added -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----- myself in the iOS client

Am I missing a step? Looking forward to hear from you and once again: I really appreciate your great work!

Cheers
Nick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant