当前位置: 首页>>代码示例>>C#>>正文


C# BigInteger.GetBytes方法代码示例

本文整理汇总了C#中BigInteger.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.GetBytes方法的具体用法?C# BigInteger.GetBytes怎么用?C# BigInteger.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BigInteger的用法示例。


在下文中一共展示了BigInteger.GetBytes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetupCrypto

        public void SetupCrypto(BigInteger key)
        {
            byte[] ServerDecryptionKey =
            {
                0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5,
                0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE
            };

            byte[] ServerEncryptionKey =
            {
                0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA,
                0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57
            };

            HMACSHA1 decryptHMAC = new HMACSHA1(ServerDecryptionKey);
            HMACSHA1 encryptHMAC = new HMACSHA1(ServerEncryptionKey);

            var decryptHash = decryptHMAC.ComputeHash(key.GetBytes());
            var encryptHash = encryptHMAC.ComputeHash(key.GetBytes());

            const int dropN = 1024; //1000 before WoTLK, 1024 now
            var buf = new byte[dropN];

            ClientConnection.Decrypt = new ARC4(decryptHash);
            ClientConnection.Encrypt = new ARC4(encryptHash);

            ClientConnection.Decrypt.Process(buf, 0, buf.Length);
            ClientConnection.Encrypt.Process(buf, 0, buf.Length);
        }
开发者ID:andy012345,项目名称:WoWServer,代码行数:29,代码来源:RealmPacketHandler.cs

示例2: Write

        public static void Write(this BinaryWriter writer, BigInteger bigInt, int numBytes, bool prefix = false)
        {
            Contract.Requires(writer != null);
            Contract.Requires(bigInt != null);
            Contract.Requires(numBytes >= 0);

            var data = bigInt.GetBytes(numBytes);

            if (prefix)
                writer.Write((byte)numBytes);

            writer.Write(data);
        }
开发者ID:hanson-huang,项目名称:Encore,代码行数:13,代码来源:IOExtensions.cs

示例3: WriteBigIntLength

        /// <summary>
        /// Writes a BigInteger to the stream, while writing the length before it
        /// </summary>
        /// <param name="bigInt">BigInteger to write</param>
        /// <param name="length">maximum numbers of bytes to write for th BigInteger</param>
        public virtual void WriteBigIntLength(BigInteger bigInt, int length)
        {
            byte[] data = bigInt.GetBytes(length);

            base.Write((byte) length);
            base.Write(data);
        }
开发者ID:Jeroz,项目名称:WCell,代码行数:12,代码来源:PrimitiveWriter.cs

示例4: WriteBigInt

        /// <summary>
        /// Writes a BigInteger to the stream
        /// </summary>
        /// <param name="bigInt">BigInteger to write</param>
        public virtual void WriteBigInt(BigInteger bigInt)
        {
            byte[] data = bigInt.GetBytes();

            base.Write(data);
        }
开发者ID:Jeroz,项目名称:WCell,代码行数:10,代码来源:PrimitiveWriter.cs

示例5: NLS

        /// <summary>
        /// Creates a new NLS login context.
        /// </summary>
        /// <param name="Username">The username to use for authentication.</param>
        /// <param name="Password">The password to use for authentication.</param>
        /// <remarks>
        /// This type does not validate the sequence from moving from one message to the next.  Ensure that you
        /// have the correct sequence of calls.
        /// </remarks>
        /// <returns>An NLS context ID.</returns>
        public NLS(string Username, string Password)
        {
            userName = Username;
            userNameAscii = Encoding.ASCII.GetBytes(userName);
            password = Password;

            byte[] rand_a = new byte[32];
            s_rand.GetNonZeroBytes(rand_a);
            a = new BigInteger(rand_a);
            a %= s_modulus;

            a = new BigInteger(ReverseArray(a.GetBytes()));
            //A = s_generator.ModPow(a, s_modulus);
            A = new BigInteger(ReverseArray(s_generator.ModPow(a, s_modulus).GetBytes()));
        }
开发者ID:MusicDemon,项目名称:BNSharp,代码行数:25,代码来源:NLS.cs

示例6: Auth_AuthChallengeResult

        //internal class AuthLogonChallenge_Result
        //{
        //    public byte m_iCommand = (byte)RealmListOpCode.CMSG_AUTH_CHALLENGE_RESULT; // 0x00 CMD_AUTH_LOGON_CHALLENGE
        //    public byte m_iError = 0;		           // 0 - ok
        //    public byte m_iUnk = 0;		           // 0x00
        //    public byte[] m_iB = new byte[32];
        //    public byte m_iGLen = 1;		           // 0x01
        //    public byte[] m_iG = new byte[1];
        //    public byte m_iNLen = 32;		           // 0x20
        //    public byte[] m_iN = new byte[32];
        //    public byte[] m_iS = new byte[32];
        //    public byte[] m_iUnk2 = new byte[16];
        //    public byte m_iUnk3 = 0;
        //}

        /// <summary>
        /// 等于 AuthLogonChallenge_Result 结构
        /// </summary>
        public Auth_AuthChallengeResult( SecureRemotePassword srp )
            : base( (long)AuthOpCode.CMSG_AUTH_CHALLENGE_RESULT, 0 )
        {
            WriterStream.Write( (byte)AuthOpCode.CMSG_AUTH_CHALLENGE_RESULT );
            WriterStream.Write( (byte)LogineErrorInfo.LOGIN_SUCCESS );
            //////////////////////////////////////////////////////////////////////////

            WriterStream.Write( (byte)0 );

            WriterStream.Write( srp.PublicEphemeralValueB.GetBytes( 32 ), 0, 32 );

            WriterStream.Write( (byte)1 );
            WriterStream.Write( srp.Generator.GetBytes( 1 ), 0, 1 );

            WriterStream.Write( (byte)32 );
            WriterStream.Write( srp.Modulus.GetBytes( 32 ), 0, 32 );

            WriterStream.Write( srp.Salt.GetBytes( 32 ), 0, 32 );

            BigInteger unknown = new BigInteger();
            unknown.GenRandomBits( 128 /* 16 * 8 */ , new Random( 10 ) );/* 随机数 16字节 */
            WriterStream.Write( unknown.GetBytes( 16 ), 0, 16 );

            WriterStream.Write( (byte)0 );
        }
开发者ID:andyhebear,项目名称:HappyQ-WowServer,代码行数:43,代码来源:Packets.cs

示例7: TestPacketReading

        public void TestPacketReading()
        {
            MemoryStream memStream = new MemoryStream();
            BinaryWriter bWriter = new BinaryWriter(memStream);

            bWriter.Write((byte)122);
            bWriter.Write((sbyte)-122);
            bWriter.Write((short)-14323);
            bWriter.Write((ushort)14323);
            bWriter.Write((int)-4124444);
            bWriter.Write((uint)4124444);
            bWriter.Write((ulong)412124553);
            bWriter.Write((long)-412124553);
            bWriter.Write((float)450.2500f);
            bWriter.Write((double)90350.45350d);
            bWriter.Write("test");

            bWriter.Write(UTF8Encoding.UTF8.GetBytes(new char[] { 't', 'e', 's', 't' }));
            bWriter.Write((byte)0);

            byte[] testBytes = new byte[] { 0x01, 0x02, 0x03, 0x02, 0x01 };
            bWriter.Write(testBytes);

            BigInteger bi = new BigInteger(1000000);
            byte[] biBytes = bi.GetBytes();
            bWriter.Write(biBytes);

            bWriter.Write((byte)biBytes.Length);
            bWriter.Write(biBytes);

            bWriter.Write(false);

            byte[] addrBytes = IPAddress.Parse("192.168.1.100").GetAddressBytes();
            bWriter.Write(addrBytes);

            bWriter.Write(UTF8Encoding.UTF8.GetBytes("tset"));
            bWriter.Write((byte)0);

            bWriter.Write(UTF8Encoding.UTF8.GetBytes(new char[] { 'z' }));

            bWriter.Write(UTF8Encoding.UTF8.GetBytes("rabooftset"));

			byte[] bytes = memStream.ToArray();

			TestPacketIn packet = new TestPacketIn(bytes);

            Assert.AreEqual((byte)122, packet.ReadByte());
            Assert.AreEqual((sbyte)-122, packet.ReadSByte());
            Assert.AreEqual((short)-14323, packet.ReadInt16());
            Assert.AreEqual((ushort)14323, packet.ReadUInt16());
            Assert.AreEqual((int)-4124444, packet.ReadInt32());
            Assert.AreEqual((uint)4124444, packet.ReadUInt32());
            Assert.AreEqual((ulong)412124553, packet.ReadUInt64());
            Assert.AreEqual((long)-412124553, packet.ReadInt64());
            Assert.AreEqual((float)450.2500f, packet.ReadFloat());
            Assert.AreEqual((double)90350.45350d, packet.ReadDouble());
            Assert.AreEqual("test", packet.ReadPascalString());
            Assert.AreEqual("test", packet.ReadCString());
            Assert.IsTrue(ByteArrayEquals(testBytes, packet.ReadBytes(5)));
            Assert.AreEqual(bi, packet.ReadBigInteger(biBytes.Length));
            Assert.AreEqual(bi, packet.ReadBigIntegerLengthValue());
            Assert.AreEqual(false, packet.ReadBoolean());
            Assert.AreEqual("192.168.1.100", packet.ReadIPAddress().Address);
            Assert.AreEqual("test", packet.ReadReversedString());
            Assert.AreEqual('z', packet.ReadChar());
            Assert.AreEqual("testfoobar", packet.ReadReversedPascalString(10));

            Assert.AreEqual(memStream.Length, packet.Length);
            Assert.AreEqual(memStream.Position, packet.Position);
        }
开发者ID:KroneckerX,项目名称:WCell,代码行数:70,代码来源:PacketInTest.cs


注:本文中的BigInteger.GetBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。