Esempio n. 1
0
        public static string GenerateHash(int version_major, string url,
                                          int hash_select, int request_id )
        {
            if( _hasht42 == null )
                GenerateTable42();
            if( _hasht45 == null )
                GenerateTable45();

            byte [] hashtable = (version_major == 3) ? _hasht45 : _hasht42;
            BrokenMD5 md5 = new BrokenMD5( (version_major == 3) ? 1 : 0 );
            byte [] hash = new byte[ 32 ];

            byte [] tmp = Encoding.ASCII.GetBytes( url );
            md5.TransformBlock( tmp, 0, tmp.Length, tmp, 0 );
            md5.TransformBlock( _copyright, 0, _copyright.Length, _copyright, 0 );

            if( request_id > 0 && version_major == 3 )
            {
                md5.TransformBlock( hashtable, hash_select * 32, 32,
                                    hashtable, hash_select * 32 );
                tmp = Encoding.ASCII.GetBytes( request_id.ToString() );
                md5.TransformFinalBlock( tmp, 0, tmp.Length );
            }
            else
            {
                md5.TransformFinalBlock( hashtable, hash_select * 32, 32 );
            }

            HashToString( md5.Hash, hash, 0 );

            return Encoding.ASCII.GetString( hash );
        }
Esempio n. 2
0
        private static void TransformString( BrokenMD5 md5, string str, bool final )
        {
            byte [] tmp = Encoding.ASCII.GetBytes( str );

            if( final )
                md5.TransformFinalBlock( tmp, 0, tmp.Length );
            else
                md5.TransformBlock( tmp, 0, tmp.Length, tmp, 0 );
        }