// // // DiffieHellman.cs: Defines a base class from which all Diffie-Hellman implementations inherit // // Author: // Pieter Philippaerts (Pieter@mentalis.org) // // (C) 2003 The Mentalis.org Team (http://www.mentalis.org/) // // // Source Code License // Copyright © 2002-2007, The Mentalis.org Team // All rights reserved. // http://www.mentalis.org/ // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: // - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. // - Neither the name of the Mentalis.org Team, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; using System.Security.Cryptography; namespace Org.Mentalis.Security.Cryptography { /// /// Defines a base class from which all Diffie-Hellman implementations inherit. /// internal abstract class DiffieHellman : AsymmetricAlgorithm { /// /// Creates an instance of the default implementation of the algorithm. /// /// A new instance of the default implementation of DiffieHellman. public static new DiffieHellman Create () { return Create ("Mono.Security.Cryptography.DiffieHellman"); } /// /// Creates an instance of the specified implementation of . /// /// The name of the implementation of DiffieHellman to use. /// A new instance of the specified implementation of DiffieHellman. public static new DiffieHellman Create (string algName) { return (DiffieHellman) CryptoConfig.CreateFromName (algName); } /// /// Initializes a new instance. /// public DiffieHellman() {} /// /// When overridden in a derived class, creates the key exchange data. /// /// The key exchange data to be sent to the intended recipient. public abstract byte[] CreateKeyExchange(); /// /// When overridden in a derived class, extracts secret information from the key exchange data. /// /// The key exchange data within which the secret information is hidden. /// The secret information derived from the key exchange data. public abstract byte[] DecryptKeyExchange(byte[] keyEx); /// /// When overridden in a derived class, exports the . /// /// true to include private parameters; otherwise, false. /// The parameters for Diffie-Hellman. public abstract DHParameters ExportParameters (bool includePrivate); /// /// When overridden in a derived class, imports the specified . /// /// The parameters for Diffie-Hellman. public abstract void ImportParameters (DHParameters parameters); #if UNUSED private byte[] GetNamedParam(SecurityElement se, string param) { SecurityElement sep = se.SearchForChildByTag(param); if (sep == null) return null; return Convert.FromBase64String(sep.Text); } #endif /// /// Reconstructs a object from an XML string. /// /// The XML string to use to reconstruct the DiffieHellman object. /// One of the values in the XML string is invalid. public override void FromXmlString (string xmlString) { if (xmlString == null) throw new ArgumentNullException (); throw new NotImplementedException(); } /// /// Creates and returns an XML string representation of the current object. /// /// true to include private parameters; otherwise, false. /// An XML string encoding of the current DiffieHellman object. public override string ToXmlString (bool includePrivateParameters) { throw new NotImplementedException(); } } }