示例#1
0
        public DiffHell(byte [] rawKey)
        {
            this.rawKey = rawKey;             //400 //144

            pks          = new PUBLICKEYSTRUC();
            pks.bType    = rawKey[0];                        //7 //6
            pks.bVersion = rawKey[1];                        //2
            pks.reserved = BitConverter.ToUInt16(rawKey, 2); //0
            pks.aiKeyAlg = BitConverter.ToUInt32(rawKey, 4); //43522

            kb = (KeyBlob)pks.bType;                         //private //public
            c  = (Calg)pks.aiKeyAlg;                         //DH_EPHEM or DH_SF

            if (kb != KeyBlob.PUBLICKEYBLOB && kb != KeyBlob.PRIVATEKEYBLOB)
            {
                throw new Exception("unsupported blob type");
            }

            dhpk = new DHPUBKEY();
            //PRIV 0x32484400. This hex value is the ASCII encoding of "DH2."
            //PUB 0x31484400. This hex value is the ASCII encoding of "DH1."
            dhpk.magic = BitConverter.ToUInt32(rawKey, 8);   //843596800 //826819584
            //Number of bits in the prime modulus, P.
            dhpk.bitlen = BitConverter.ToUInt32(rawKey, 12); //1024
            uint byteLen = dhpk.bitlen / 8;                  //128

            this.SetSizeAndPosition(dhpk.bitlen);

            bool revBytes = true;

            if (kb == KeyBlob.PRIVATEKEYBLOB)
            {
                P = Format.GetBytes(this.rawKey, ypPos, ypLen, revBytes);
                G = Format.GetBytes(this.rawKey, gPos, gLen, revBytes);
                X = Format.GetBytes(this.rawKey, xPos, xLen, revBytes);
            }
            if (kb == KeyBlob.PUBLICKEYBLOB)
            {
                Y = Format.GetBytes(this.rawKey, ypPos, ypLen, revBytes);
            }
        }
示例#2
0
		public DiffHell(byte [] rawKey)
		{
			this.rawKey = rawKey; //400 //144

			pks = new PUBLICKEYSTRUC();
			pks.bType = rawKey[0]; //7 //6
			pks.bVersion = rawKey[1]; //2
			pks.reserved = BitConverter.ToUInt16(rawKey, 2); //0
			pks.aiKeyAlg = BitConverter.ToUInt32(rawKey, 4); //43522

			kb = (KeyBlob) pks.bType; //private //public
			c = (Calg) pks.aiKeyAlg; //DH_EPHEM or DH_SF
			
			if(kb != KeyBlob.PUBLICKEYBLOB && kb != KeyBlob.PRIVATEKEYBLOB)
				throw new Exception("unsupported blob type");

			dhpk = new DHPUBKEY();
			//PRIV 0x32484400. This hex value is the ASCII encoding of "DH2."
			//PUB 0x31484400. This hex value is the ASCII encoding of "DH1."
			dhpk.magic = BitConverter.ToUInt32(rawKey, 8); //843596800 //826819584
			//Number of bits in the prime modulus, P.  
			dhpk.bitlen = BitConverter.ToUInt32(rawKey, 12); //1024
			uint byteLen = dhpk.bitlen / 8; //128

			this.SetSizeAndPosition(dhpk.bitlen);

			bool revBytes = true;
			if(kb == KeyBlob.PRIVATEKEYBLOB)
			{
				P = Format.GetBytes(this.rawKey, ypPos, ypLen, revBytes); 
				G = Format.GetBytes(this.rawKey, gPos, gLen, revBytes); 
				X = Format.GetBytes(this.rawKey, xPos, xLen, revBytes);
			}
			if(kb == KeyBlob.PUBLICKEYBLOB)
			{
				Y = Format.GetBytes(this.rawKey, ypPos, ypLen, revBytes);
			}
		}