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


C# HMACMD5.TransformFinalBlock方法代码示例

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


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

示例1: CheckD

		public void CheckD (string testName, byte[] key, byte[] data, byte[] result) 
		{
			algo = new HMACMD5 ();
			algo.Key = key;
			// LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
			algo.TransformFinalBlock (data, 0, data.Length);
			Assert.AreEqual (result, algo.Hash, testName + "d");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:HMACMD5Test.cs

示例2: CheckE

		public void CheckE (string testName, byte[] key, byte[] data, byte[] result) 
		{
			algo = new HMACMD5 ();
			algo.Key = key;
			byte[] copy = new byte [data.Length];
			// LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
			for (int i=0; i < data.Length - 1; i++)
				algo.TransformBlock (data, i, 1, copy, i);
			algo.TransformFinalBlock (data, data.Length - 1, 1);
			Assert.AreEqual (result, algo.Hash, testName + "e");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:HMACMD5Test.cs

示例3: Authenticate

        /// <summary>
        /// Authenticates a socket before accepting into
        /// a permanent connection (it's connection attempt
        /// may yet be rejected.)
        /// </summary>
        /// <param name="socketObj">The object to cast into a socket to query.</param>
        public void Authenticate(Object socketObj)
        {
            Socket s = (Socket)socketObj;

            int rconConId = this.NextRconID; //Don't bother sending CreateRootUser this ID. The socket
            if ( rconConId == -1 ) return; //doesn't exist for long enough for us to care. But it's important that it's there.

            if ( rconUsers == null ) {
                CreateRootUser( s );
                return;
            }

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat( "<{0}.{1}@{2}>",
                System.Diagnostics.Process.GetCurrentProcess().Id,
                DateTime.Now.ToString( "ddmmyyhhmmss" ),
                System.Environment.UserDomainName );

            string authmsg = "authenticate " + sb.ToString();
            int offset = 0;
            SocketError errorCode;
            do {
                try {
                    offset += s.Send( IRCProtocol.Ascii.GetBytes( authmsg ),
                        offset, authmsg.Length - offset, SocketFlags.None, out errorCode );
                }
                catch ( SocketException ) {
                    s.Close();
                    return; //Give up. They can reconnect.
                }
            } while ( offset < authmsg.Length );

            if ( errorCode != SocketError.Success ) { s.Close(); return; }

            //Get Auth response.
            byte[] recvBuf = new byte[rconfig.SocketBufferSize];
            offset = s.Receive( recvBuf, 0, rconfig.SocketBufferSize, SocketFlags.None, out errorCode );
            if ( offset == 0 || errorCode != SocketError.Success ) { s.Close(); return; }
            string authReply = IRCProtocol.Ascii.GetString( recvBuf, 0, offset );

            //Parse into name/hash and verify both for correctness.
            string[] unameAndHash = authReply.Split( ' ' );
            if ( unameAndHash.Length != 2 ) { s.Close(); return; }

            //Verify username.
            string username = unameAndHash[0];
            Nullable<RconUserFile.RconUser> rc = rconUsers.GetUser(username);
            if ( rc == null ) { s.Close(); return; }

            //Verify their hash.
            string theirHash = unameAndHash[1];
            string pass = rc.Value.Password;

            HMACMD5 hmac = new HMACMD5( IRCProtocol.Ascii.GetBytes( pass ) );
            hmac.Initialize();
            hmac.TransformFinalBlock( IRCProtocol.Ascii.GetBytes( sb.ToString() ), 0, theirHash.Length );
            string ourHash = RconUserFile.GetHashFromDigest( hmac.Hash );

            if ( !ourHash.Equals( theirHash ) ) { s.Close(); return; }

            authmsg = "success";
            offset = 0;
            do {
                try {
                    offset += s.Send( IRCProtocol.Ascii.GetBytes( authmsg ),
                        offset, authmsg.Length - offset, SocketFlags.None, out errorCode );
                }
                catch ( SocketException ) {
                    s.Close();
                    return; //Give up. They can reconnect.
                }
            } while ( offset < authmsg.Length );

            if ( errorCode != SocketError.Success ) { s.Close(); return; }

            //DO IT MAD AMOUNTS OF ARRAY LOOKUPS FOR NO REASON. L2TEMP VARIABLE PLZ
            rconConnections[rconConId] = new SocketPipe( s, rconConId, 30000, 5000, 0 );
            rconConnections[rconConId].OnReceive += new SocketPipe.ReceiveData( OnReceive );
            rconConnections[rconConId].OnDisconnect += new SocketPipe.NoParams( OnDisconnect );

            Thread t = new Thread( new ThreadStart( rconConnections[rconConId].ConstantPump ) );
            t.Start(); //Start sending anything we can :D
            rconConnections[rconConId].ConstantSiphon(); //Consume current thread generated by ConstantAccept.
        }
开发者ID:aarondl,项目名称:Project-2Q,代码行数:90,代码来源:Rcon.cs


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