DHKeyExchangeCrypto.cs throws exception while encrypting data

Hi,
I am using the reference implementation of Encrypt Decrypt C# implementation:

But it is throwing exception for a public key given by NDHM PHR app:
Exception:
at Org.BouncyCastle.Asn1.DefiniteLengthInputStream.ToArray()
at Org.BouncyCastle.Asn1.Asn1InputStream.CreatePrimitiveDerObject(Int32 tagNo, DefiniteLengthInputStream defIn, Byte[][] tmpBuffers)
at Org.BouncyCastle.Asn1.Asn1InputStream.BuildObject(Int32 tag, Int32 tagNo, Int32 length)
at Org.BouncyCastle.Asn1.Asn1InputStream.ReadObject()
at Org.BouncyCastle.Asn1.Asn1Object.FromByteArray(Byte[] data)
at Org.BouncyCastle.Security.PublicKeyFactory.CreateKey(Byte[] keyInfoData)
at In.ProjectEKA.HipService.EncryptionBit.EncrytorDemo.GetPublicKeyFrom(String publicKey) in

Below are an example public key and the algo details:
“cryptoAlg”: “ECDH”,
“curve”: “curve25519”,
“dhPublicKey”: {
“expiry”: “2020-11-07T13:15:33.501894”,
“parameters”: “Ephemeral public key”,
“keyValue”: “BH1zmG+pTHyoFPM5jOok6ZXeh58OnEtvvyiHY3d3TmqXWuChftXLD73Mi5sUvjJm+R91Yq2yNSj6x89PrSKtXI4=”
},

Please let me know if there is an update to the c# code.

Hi @chaya,

There is no change in C# implementation. Let us check this and get back to you. In the meantime if you get it working please share the solution here.

Thanks!

Thanks.
Please note that I am able to encrypt using the same public key in the java sample implementation.
Could it be issue with the version of BouncyCastle. I am using 1.8.8

Regards

@chaya @dheerajp were you able to get over this problem? I am trying to solve the same problem. The encryption algorithm just doesnt work in C#.

How did you solve this?