public DiffieHellmanPublicKey(DiffieHellmanGroupType group, int keySize, BigInteger x) { _group = group; _keySize = keySize; _x = x; DiffieHellmanGroup dhg = DiffieHellmanGroup.GetGroup(group, keySize); VerifyPublicKey(_keySize, dhg.P, dhg.G, x); }
public DiffieHellman(DiffieHellmanGroupType group, KeyAgreementKeyDerivationFunction kdFunc, KeyAgreementKeyDerivationHashAlgorithm kdHashAlgo) : base(kdFunc, kdHashAlgo) { _group = group; DiffieHellmanGroup dhg = DiffieHellmanGroup.GetGroup(_group); _keySize = dhg.KeySize; _p = dhg.P; _g = dhg.G; _privateKey = GeneratePrivateKey(_p); }
public DiffieHellmanPublicKey(byte[] publicKey) { using (MemoryStream mS = new MemoryStream(publicKey, false)) { BinaryReader bR = new BinaryReader(mS); if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "DH") { throw new InvalidDataException("Invalid DiffieHellmanPublicKey data format."); } switch (bR.ReadByte()) //version { case 2: _keySize = bR.ReadInt32(); _group = (DiffieHellmanGroupType)bR.ReadByte(); switch (_group) { case DiffieHellmanGroupType.RFC3526: DiffieHellmanGroup dhg = DiffieHellmanGroup.GetGroup(_group, _keySize); _p = dhg.P; _g = dhg.G; _x = ReadPositiveNumber(bR.ReadBuffer()); break; case DiffieHellmanGroupType.None: _p = ReadPositiveNumber(bR.ReadBuffer()); _g = ReadPositiveNumber(bR.ReadBuffer()); _x = ReadPositiveNumber(bR.ReadBuffer()); break; default: throw new NotSupportedException("DiffieHellmanGroup type not supported."); } break; default: throw new InvalidDataException("DiffieHellmanPublicKey data format version not supported."); } } VerifyPublicKey(_keySize, _p, _g, _x); }
public DiffieHellmanPublicKey(byte[] publicKey) { using (MemoryStream mS = new MemoryStream(publicKey, false)) { BincodingDecoder decoder = new BincodingDecoder(mS, "DH"); switch (decoder.Version) { case 1: _keySize = decoder.DecodeNext().GetIntegerValue(); _group = (DiffieHellmanGroupType)decoder.DecodeNext().GetByteValue(); switch (_group) { case DiffieHellmanGroupType.RFC3526: DiffieHellmanGroup dhg = DiffieHellmanGroup.GetGroup(_group, _keySize); _p = dhg.P; _g = dhg.G; _x = ReadPositiveNumber(decoder.DecodeNext().Value); break; case DiffieHellmanGroupType.None: _p = ReadPositiveNumber(decoder.DecodeNext().Value); _g = ReadPositiveNumber(decoder.DecodeNext().Value); _x = ReadPositiveNumber(decoder.DecodeNext().Value); break; default: throw new NotSupportedException("DiffieHellmanGroup type not supported."); } break; default: throw new InvalidDataException("DiffieHellmanPublicKey data format version not supported."); } } VerifyPublicKey(_keySize, _p, _g, _x); }