コード例 #1
0
        /// Encodes the specified string.
        /// @param text The string to encode.
        /// @returns The encoded string.
        public string Encode(string text)
        {
            var buffer = Encoding.Default.GetBytes(text);
            var hash   = MD4.Create().ComputeHash(buffer);

            return(HexCodec.GetString(hash));
        }
コード例 #2
0
        public override void Create()
        {
            // try creating ourselve using Create
            HashAlgorithm h = MD4.Create("MD4Managed");

            Assert.IsTrue((h is MD4Managed), "MD4Managed");
        }
コード例 #3
0
        public static long SerializationIndexFromObjectIdentifier(ObjectIdentifier objectID)
        {
            byte[] bytes;
            var    md4 = MD4.Create();

            if (objectID.fileType == FileType.MetaAssetType || objectID.fileType == FileType.SerializedAssetType)
            {
                // TODO: Variant info
                // NOTE: ToString() required as unity5 used the guid as a string to hash
                bytes = Encoding.ASCII.GetBytes(objectID.guid.ToString());
                md4.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
                bytes = BitConverter.GetBytes((int)objectID.fileType);
                md4.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
            }
            // Or path
            else
            {
                bytes = Encoding.ASCII.GetBytes(objectID.filePath);
                md4.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
            }

            bytes = BitConverter.GetBytes(objectID.localIdentifierInFile);
            md4.TransformFinalBlock(bytes, 0, bytes.Length);
            var hash = BitConverter.ToInt64(md4.Hash, 0);

            return(hash);
        }
コード例 #4
0
ファイル: MD4Test.cs プロジェクト: xiaochuwang/mono
        public virtual void Create()
        {
            // create the default implementation
            HashAlgorithm h = MD4.Create();

            Assert("MD4Managed", (h is MD4Managed));
            // Note: will fail is default is changed in machine.config
        }
コード例 #5
0
        public static string GenerateInternalFileName(string name)
        {
            var md4   = MD4.Create();
            var bytes = Encoding.ASCII.GetBytes(name);

            md4.TransformFinalBlock(bytes, 0, bytes.Length);
            return("CAB-" + BitConverter.ToString(md4.Hash, 0).ToLower().Replace("-", ""));
        }
コード例 #6
0
        private static int ComputeGuid(Type t) // TODO why does scriptable build pipeline not provide this
        {
            string hashGenerator = "s\0\0\0" + t.Namespace + t.Name;

            using (var md4 = MD4.Create())
            {
                byte[] hash = md4.ComputeHash(Encoding.UTF8.GetBytes(hashGenerator));
                return(BitConverter.ToInt32(hash, 0));
            }
        }
コード例 #7
0
        string GenLink(string filename)
        {
            FileInfo fi = new FileInfo(filename);

            if (fi.Exists)
            {
                AICHHash      aich    = new AICHHash(fi.Length);
                List <byte[]> hashset = new List <byte[]>();
                MD4           md4     = MD4.Create();
                using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    byte[] buffer = new byte[EMPARTSIZE];
                    int    readCount;
                    do
                    {
                        readCount = fs.Read(buffer, 0, buffer.Length);
                        if (readCount > 0)
                        {
                            hashset.Add(md4.ComputeHash(buffer, 0, readCount));
                            aich.CalcAICH(buffer, 0, readCount);
                            if (worker != null && worker.WorkerReportsProgress)
                            {
                                worker.ReportProgress((int)(fs.Position * 100 / fs.Length), this);
                            }
                        }
                        else if (fs.Length % EMPARTSIZE == 0)
                        {
                            hashset.Add(md4.ComputeHash(new byte[] { }));
                        }
                    }while (readCount != 0);
                }
                byte[] filehash = new byte[16];
                if (hashset.Count == 1)
                {
                    filehash = hashset[0];
                }
                else
                {
                    filehash = md4.ComputeHash(hashset.SelectMany(bytes => bytes).ToArray());
                }
                return(string.Format("ed2k://|file|{0}|{1}|{2}|h={3}|/", System.Web.HttpUtility.UrlEncode(fi.Name), fi.Length, String.Concat(filehash.Select(b => b.ToString("X2")).ToArray()), aich.RootHash));
            }
            else
            {
                throw new FileNotFoundException();
            }
        }
コード例 #8
0
ファイル: ChallengeResponse2.cs プロジェクト: zhxjdwh/revenj
        static byte[] Compute_NTLM_Password(string password)
        {
            var buffer = new byte [21];

            // create NT password
            MD4 md4 = MD4.Create();

            byte[] data = ((password == null) ? (new byte [0]) : (Encoding.Unicode.GetBytes(password)));
            byte[] hash = md4.ComputeHash(data);
            Buffer.BlockCopy(hash, 0, buffer, 0, 16);

            // clean up
            Array.Clear(data, 0, data.Length);
            Array.Clear(hash, 0, hash.Length);

            return(buffer);
        }
コード例 #9
0
        /// <summary>
        /// Computes an NT hash value with a password using NTOWFv1.
        /// </summary>
        /// <param name="password">A password to compute hash</param>
        /// <exception cref="ArgumentNullException">Raised if password is null</exception>
        /// <returns>An NT hash value</returns>
        public static byte[] GetHashWithNTOWFv1(string password)
        {
            if (password == null)
            {
                // Will be changed to StackSdkException after StackSdkException class is updated.
                throw new ArgumentNullException("password");
            }

            byte[] hash;

            using (MD4 md4 = MD4.Create())
            {
                // Get password byte array
                byte[] passwordBuffer = Encoding.Unicode.GetBytes(password);
                hash = md4.ComputeHash(passwordBuffer);
            }

            return(hash);
        }
コード例 #10
0
ファイル: PKCS1.cs プロジェクト: vvuk/Emby
        static internal HashAlgorithm CreateFromName(string name)
        {
#if FULL_AOT_RUNTIME
            switch (name)
            {
            case "MD2":
                return(MD2.Create());

            case "MD4":
                return(MD4.Create());

            case "MD5":
                return(MD5.Create());

            case "SHA1":
                return(SHA1.Create());

            case "SHA256":
                return(SHA256.Create());

            case "SHA384":
                return(SHA384.Create());

            case "SHA512":
                return(SHA512.Create());

            case "RIPEMD160":
                return(RIPEMD160.Create());

            default:
                try {
                    return((HashAlgorithm)Activator.CreateInstance(Type.GetType(name)));
                }
                catch {
                    throw new CryptographicException("Unsupported hash algorithm: " + name);
                }
            }
#else
            return(HashAlgorithm.Create(name));
#endif
        }
コード例 #11
0
 static SecurityUtils()
 {
     MD4Singleton = MD4.Create();
 }
コード例 #12
0
 public V3Store(string storeBasePath)
     : base(storeBasePath, "v3\\p", "v3\\w", MD4.Create(), V3Store.BinaryHashLength, V3Store.BinaryHashOffset)
 {
 }
コード例 #13
0
ファイル: Encrypt.cs プロジェクト: Bgoon/GKit
 public static byte[] ComputeMD4Binary(byte[] data)
 {
     using (HashAlgorithm cryptor = MD4.Create()) {
         return(cryptor.ComputeHash(data));
     }
 }