Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ECDH.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4
6{
10 public static class ECDH
11 {
22 public static byte[] GetSharedKey(byte[] LocalPrivateKey, byte[] RemotePublicKey,
24 {
25 PointOnCurve PublicKey = Curve.Decode(RemotePublicKey);
26 PointOnCurve P = Curve.ScalarMultiplication(LocalPrivateKey, PublicKey, true);
27
28 byte[] B = P.X.ToByteArray();
29
30 if (B.Length != Curve.OrderBytes)
31 Array.Resize(ref B, Curve.OrderBytes);
32
33 Array.Reverse(B); // Most significant byte first.
34
35 return HashFunction(B);
36 }
37 }
38}
Implements the Elliptic Curve Diffie-Hellman (ECDH) algorithm.
Definition: ECDH.cs:11
static byte[] GetSharedKey(byte[] LocalPrivateKey, byte[] RemotePublicKey, HashFunctionArray HashFunction, EllipticCurve Curve)
Gets a shared key using the Elliptic Curve Diffie-Hellman (ECDH) algorithm.
Definition: ECDH.cs:22
Abstract base class for elliptic curves.
virtual PointOnCurve Decode(byte[] Point)
Decodes an encoded point on the curve.
int OrderBytes
Number of bytes required to represent the order of the curve.
PointOnCurve ScalarMultiplication(BigInteger N, PointOnCurve P, bool Normalize)
Performs the scalar multiplication of N *P .
delegate byte[] HashFunctionArray(byte[] Data)
Delegate to hash function.
HashFunction
Hash method enumeration.
Definition: Hashes.cs:28
Represents a point on a curve.
Definition: PointOnCurve.cs:11