4using System.Threading.Tasks;
15 private const string E2eCounterName =
"E2EE.Counter";
34 this.defaultSymmetricCipher?.Dispose();
35 this.defaultSymmetricCipher =
null;
49 set => this.prev = value;
100 foreach (XmlAttribute Attr
in Xml.Attributes)
105 return this.
CreatePublic(Convert.FromBase64String(Attr.Value));
108 return this.
CreatePrivate(Convert.FromBase64String(Attr.Value));
121 return this.
ToXml(
string.Empty);
128 public string ToXml(
string ParentNamespace)
130 StringBuilder Xml =
new StringBuilder();
131 this.
ToXml(Xml, ParentNamespace);
132 return Xml.ToString();
140 public void ToXml(StringBuilder Xml,
string ParentNamespace)
144 Xml.Append(
" pub=\"");
148 if (ns != ParentNamespace)
150 Xml.Append(
"\" xmlns=\"");
196 public abstract byte[]
Sign(
byte[] Data);
203 public abstract byte[]
Sign(Stream Data);
211 public abstract bool Verify(
byte[] Data,
byte[] Signature);
219 public abstract bool Verify(Stream Data,
byte[] Signature);
224 public virtual bool Safe =>
true;
229 public virtual bool Slow =>
false;
239 StringBuilder Xml =
new StringBuilder();
240 this.
ToXml(Xml,
string.Empty);
241 return Xml.ToString();
245 public override abstract bool Equals(
object obj);
262 if (this.SupportsSignatures)
271 if (this.PostQuantumCryptography)
283 get => this.defaultSymmetricCipher;
284 set => this.defaultSymmetricCipher = value ?? this.defaultSymmetricCipher;
Abstract base class for End-to-End encryption schemes.
abstract byte[] Sign(Stream Data)
Signs binary data using the local private key.
virtual bool Slow
If implementation is slow, compared to other options.
async Task< uint > GetNextCounter()
Gets the next counter value.
virtual bool SupportsSignatures
If signatures are supported.
abstract byte[] Sign(byte[] Data)
Signs binary data using the local private key.
abstract bool SharedSecretUseCipherText
If the recipient needs a cipher text to generate the same shared secret.
virtual IE2eSymmetricCipher DefaultSymmetricCipher
Default symmetric cipher.
abstract IE2eEndpoint Create(int SecurityStrength)
Creates a new key.
abstract bool Verify(Stream Data, byte[] Signature)
Verifies a signature.
virtual bool Safe
If endpoint is considered safe (i.e. there are no suspected backdoors)
abstract byte[] GetSharedSecretForEncryption(IE2eEndpoint RemoteEndpoint, IE2eSymmetricCipher Cipher, out byte[] CipherText)
Gets a shared secret for encryption, and optionally a corresponding cipher text.
string ToXml(string ParentNamespace)
Exports the public key information to XML.
virtual void Dispose()
IDisposable.Dispose
abstract IE2eEndpoint CreatePublic(byte[] PublicKey)
Creates a new endpoint given a public key.
abstract IE2eEndpoint CreatePrivate(byte[] Secret)
Creates a new endpoint given a private key.
override string ToString()
abstract override bool Equals(object obj)
virtual bool PostQuantumCryptography
If post-quantum cryptography is used.
abstract bool Verify(byte[] Data, byte[] Signature)
Verifies a signature.
void ToXml(StringBuilder Xml, string ParentNamespace)
Exports the public key information to XML.
IE2eEndpoint Parse(XmlElement Xml)
Parses endpoint information from an XML element.
E2eEndpoint(IE2eSymmetricCipher DefaultSymmetricCipher)
Abstract base class for End-to-End encryption schemes.
virtual string Namespace
Namespace of the E2E encryption scheme
string ToXml()
Exports the public key information to XML.
abstract override int GetHashCode()
abstract byte[] GetSharedSecretForDecryption(IE2eEndpoint RemoteEndpoint, byte[] CipherText)
Gets a shared secret for decryption.
int Score
Provides a score for the endpoint. More features, higher score.
abstract string PublicKeyBase64
Remote public key, as a Base64 string.
abstract int SecurityStrength
Security strength of End-to-End encryption scheme.
IE2eEndpoint Previous
Previous keys.
abstract string LocalName
Local name of the E2E encryption scheme
abstract byte[] PublicKey
Remote public key.
Class managing end-to-end encryption.
const string IoTHarmonizationE2ECurrent
Current namespace for End-to-End encryption.
Static class managing persistent counters.
static Task< long > IncrementCounter(CaseInsensitiveString Key)
Increments a counter.
Abstract base class for End-to-End encryption schemes.
Interface for symmetric ciphers.