21 private readonly
bool hasPrivateKey;
22 private readonly
string publicKeyBase64;
34 this.hasPrivateKey =
true;
35 this.publicKeyBase64 = Convert.ToBase64String(this.publicKey);
48 this.curve = ReferenceCurve;
49 this.hasPrivateKey =
false;
50 this.publicKeyBase64 = Convert.ToBase64String(this.publicKey);
121 string Key = LocalKey.PublicKeyBase64 +
";" + RemoteKey.
PublicKeyBase64;
123 if (sharedSecrets.TryGetValue(Key, out
byte[] SharedKey))
124 SharedKey = (
byte[])SharedKey.Clone();
128 sharedSecrets[Key] = (
byte[])SharedKey.Clone();
139 public override byte[]
Sign(
byte[] Data)
141 if (!this.hasPrivateKey)
142 throw new InvalidOperationException(
"Signing requires private key.");
144 byte[] Signature = this.curve.Sign(Data,
false);
154 public override byte[]
Sign(Stream Data)
156 if (!this.hasPrivateKey)
157 throw new InvalidOperationException(
"Signing requires private key.");
159 byte[] Signature = this.curve.Sign(Data,
false);
173 return this.curve.Verify(Data,
PublicKey,
false, Signature);
185 return this.curve.Verify(Data,
PublicKey,
false, Signature);
194 public override bool Verify(
byte[] Data,
byte[] Signature)
196 return this.
Verify(Data, this.publicKey, Signature);
205 public override bool Verify(Stream Data,
byte[] Signature)
207 return this.
Verify(Data, this.publicKey, Signature);
214 this.curve.
CurveName.Equals(EcEndpoint.curve.CurveName) &&
215 this.publicKeyBase64.Equals(EcEndpoint.publicKeyBase64);
221 int Result = this.curve.CurveName.GetHashCode();
222 Result ^= Result << 5 ^ this.publicKeyBase64.GetHashCode();
Abstract base class for End-to-End encryption schemes.
virtual IE2eSymmetricCipher DefaultSymmetricCipher
Default symmetric cipher.
Abstract base class for Elliptic Curve endpoints.
override byte[] Sign(Stream Data)
Signs binary data using the local private key.
override bool SharedSecretUseCipherText
If the recipient needs a cipher text to generate the same shared secret.
override byte[] GetSharedSecretForDecryption(IE2eEndpoint RemoteEndpoint, byte[] CipherText)
Gets a shared secret for decryption.
override bool Equals(object obj)
readonly byte[] publicKey
Remote public key.
override byte[] PublicKey
Remote public key.
EllipticCurveEndpoint(EllipticCurve Curve, IE2eSymmetricCipher DefaultSymmetricCipher)
Abstract base class for Elliptic Curve endpoints.
override int GetHashCode()
bool Verify(byte[] Data, byte[] PublicKey, byte[] Signature)
Verifies a signature.
EllipticCurve Curve
Elliptic Curve
override string PublicKeyBase64
Remote public key, as a Base64 string.
string CurveName
Name of elliptic curve
override bool Verify(Stream Data, byte[] Signature)
Verifies a signature.
override bool Verify(byte[] Data, byte[] Signature)
Verifies a signature.
EllipticCurveEndpoint(byte[] PublicKey, EllipticCurve ReferenceCurve, IE2eSymmetricCipher DefaultSymmetricCipher)
Abstract base class for Elliptic Curve endpoints.
override byte[] GetSharedSecretForEncryption(IE2eEndpoint RemoteEndpoint, IE2eSymmetricCipher Cipher, out byte[] CipherText)
Gets a shared secret for encryption, and optionally a corresponding cipher text.
bool HasPrivateKey
If the key contains a private key.
static byte[] GetSharedKey(EllipticCurveEndpoint LocalKey, IE2eEndpoint RemoteKey)
Shared secret, for underlying symmetric cipher.
bool Verify(Stream Data, byte[] PublicKey, byte[] Signature)
Verifies a signature.
override byte[] Sign(byte[] Data)
Signs binary data using the local private key.
EllipticCurve PrevCurve
Previous Elliptic Curve
Implements an in-memory cache.
Abstract base class for elliptic curves.
virtual byte[] PublicKey
Encoded public key
virtual byte[] GetSharedKey(byte[] RemotePublicKey, HashFunctionArray HashFunction)
Gets a shared key using the Elliptic Curve Diffie-Hellman (ECDH) algorithm.
Contains methods for simple hash calculations.
static byte[] ComputeSHA256Hash(byte[] Data)
Computes the SHA-256 hash of a block of binary data.
Abstract base class for End-to-End encryption schemes.
byte[] PublicKey
Remote public key.
string PublicKeyBase64
Remote public key, as a Base64 string.
Interface for symmetric ciphers.