Hello,
I am attempting to perform a Diffie Hellman Keyexchange with a server running on .Net.
However, the secretKey I am creating on the client side does not match with the secretKey on the server side, which I have for testing purposes.
I can import the server secret key as a SymetricKey
, and if I use it to seal and open a box, it works. However, if I seal the box with my client key, I can not open it with the server shared key.
I create the SymetricKey like this:
let sharedHash = SHA256.self
let sharedInfo = serverPublicKey.rawRepresentation
let sharedLength = 32
let symetricKey = sharedSecret.x963DerivedSymmetricKey(
using: sharedHash,
sharedInfo: Data(),
outputByteCount: sharedLength)
The server key is created using .Net like this:
bob.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash;
bob.HashAlgorithm = CngAlgorithm.Sha256;
bobPublicKey = bob.PublicKey.ToByteArray();
bobKey = bob.DeriveKeyMaterial(CngKey.Import(Alice.alicePublicKey, CngKeyBlobFormat.EccPublicBlob));
My assumption is the keys should be the same. Is that correct?
How can I find out what format the server key is in? The .Net documentation is not particularly precise on that
You can find a Playground of my code, and when you google for ECDiffieHellmanCng Class
, you will find an example on what .Net does.
Any help is appreciated