folder Tahribat.com Forumları
linefolder Bilişim Güvenliği
linefolder Md5 Nedir ? (Bilmeyenlere Kaynak Olsun )Bilelim Öğrenelim



Md5 Nedir ? (Bilmeyenlere Kaynak Olsun )Bilelim Öğrenelim

  1. KısayolKısayol reportŞikayet pmÖzel Mesaj
    gambit
    gambit's avatar
    Kayıt Tarihi: 25/Ağustos/2005
    Erkek

    selamlar uzun süredir tahribata üye olmama rağmen iş yoğunluğu nedeni ile foruma bir süredir giremiyordum ve de haklı olarak üyeliğimde sona ermiş bende geldim ve de ilk security bölümüne bir bakayım dedim direk dikkatimi MD5 hash algoritması çekti


     


    bilmeyen arkadaşlar için de böyle bir topic açmayı uygun buldum umarım yardımcı olur


    (makale alıntıdır ... bilgilerinize)


    Nedir bu MD5 ? Yenir mi?


    MD5 bir hashing algoritmasidir. Algoritmanin detayi icin
    http://www.faqs.org/rfcs/rfc1321.html
    adresinden gorebilirsiniz.


    Hashing nedir?


    Hashing denilen sey hash üretme islemidir. Puha bu mudur yane diyen cok olmustur herhalde.
    Belli bir stringden(text) belli bir algoritma ile belli uzunlukda bir String elde etmeye yarar.
    Fakat her stringden farkli bir hash olusur. Ayri stringden ayni hashler OLUSAMAZ (diyorlarki 2^128 de 1 ihtimal falan)
    CEO muz gecen gunku code campimizda ayni hashe sahip iki farkli dosya bulundugunu soyledi.
    Ben halen gormeden inanmam diyenlerdenim :)


    MD5 128-bit digest SHA1 ise 160-bit digest olustur.


    Evet simdi ana hatlari aldik. Bilmemiz gereken son sey ise bu encyrption tek yonludur. Hashe donusen veri geri dondurulemez.


    Nerelerde kullanilir.


    En onemli alanlari clear text tutulan passwordlerde olabilir. Mesela database a username password bilgisini tutucaz.
    password kolonunu clear text tuttugumuz zaman sistem bir sekilde indirilirse texte hemen ulasilir en azindan bu veriye kadar
    ulasabilcek adami biraz urastirmak lazim diye dusunuyorum.Sniff edildiginde veriler gorulse de Tam ne oldugu cözülemez. Client side da javascriptle bile md5 yapabildiginize gore bu iyi bisi...


    Databasedeki hashli veri bu hashlenmis veriyle karsilastirilir.


    Ikinci en onemli alani ise dosyalarin checksumi olarak kullanilir dosyanin degistirilip degistirilmedigini anlamak icin
    kullanilabilinir. Bir mesajin integritysini cozmeye birebirdir. O yuzden Signing(Emaildeki signing) de de kullanılır.


    UFFFF Amma cok annattin lan diyenlere daha anlatasim var ama artik biraz da security manyaklarindan cikip JAVA (cavaaaa diye okuyunuz)
    manyakligina donelim.
    iste size cok kucuk bir kod..

    package md5;

    import java.security.MessageDigest;

    public class Md5Test
    {
    public Md5Test()
    {
    }

    public String createMd5Hash(String hashingAlgorithm,String stringToMd5)
    {
    String plainText;
    StringBuffer hexString = new StringBuffer();
    try
    {
    MessageDigest md=MessageDigest.getInstance(hashingAlgorithm);
    //Pazara gidelim bir digest alalim -- SHA1,MD5 ....
    md.update(stringToMd5.getBytes());
    byte[] digest = md.digest();

    for (int i = 0; i < digest.length; i++)
    {
    plainText = Integer.toHexString(0xFF & digest);
    if (plainText.length() < 2) {
    plainText = "0" + plainText;
    }
    hexString.append(plainText);
    }
    }
    catch(Exception e )
    {
    e.printStackTrace();
    }
    return hexString.toString();
    }

    public static void main(String args[])
    {
    String s = "Hepinize secure ve javaaa dolu gunler dilegiyle.";
    Md5Test md5= new Md5Test();
    System.out.print(md5.createMd5Hash("MD5",s));
    }
    }


    Simdi birazda burda olan olaydan bahsedelim.
    getInstance ile bir Message Digest alinir.Alirken hangi algoritmayi kullancagimizi soyledik.
    Byte array olarak istedigimiz veriyi update fonksiyonu ile yolladik. ve digest() fonksiyonunu cagrirak
    byte arraye kusturduk.//sevdim bu lafi //


    Elimizde hash var artik. Bundan sonraki kisim byte arrayi hexStringe cevirmekle alakali.


    MCP MCSA 2003 MCSE 2003
  2. KısayolKısayol reportŞikayet pmÖzel Mesaj
    m3rt
    m3rt's avatar
    Kayıt Tarihi: 24/Aralık/2002
    Erkek
    zumsuk bunu yazdı:


    Ya çok sağol ama birşey sorucam bu md5leri çözen bir program gördüm rus hacklerde ama videoyu tekrar tekrar izledim brute force kullanmıyordu bana bu brute force kullanmadan çözen program lazım holyone nın var ama oda brute force lütfen yardım edermisin acil =((


    yazıyı tekrar bi oku derim..
  3. KısayolKısayol reportŞikayet pmÖzel Mesaj
    tagext
    tagext's avatar
    Üstün Hizmet Madalyası Başarı Madalyası
    Kayıt Tarihi: 25/Temmuz/2002
    Erkek

    aha buda MD5 JAVA KODU işlem budur
    import java.io.*;
    public class MD5 {
        private class MD5State {
            public void reset() {
                state[0] = 0x67452301;
                state[1] = 0xefcdab89;
                state[2] = 0x98badcfe;
                state[3] = 0x10325476;
                bitCount = 0L;
            }
        public void copy(MD5State from) {
                System.arraycopy(from.buffer, 0, buffer, 0, buffer.length);
                System.arraycopy(from.state, 0, state, 0, state.length);
                valid = from.valid;
                bitCount = from.bitCount;
            }
            public boolean valid;
            public int state[];
            public long bitCount;
            public byte buffer[];
            public MD5State() {
                valid = true;
                state = new int[4];
                buffer = new byte[64];
                reset();
            }
        }
        public MD5() {
            workingState = new MD5State();
            finalState = new MD5State();
            decodeBuffer = new int[16];
            reset();
        }
        public byte[] getHash() {
            if(!finalState.valid) {
                finalState.copy(workingState);
                long bitCount = finalState.bitCount;
                int leftOver = (int)((finalState.bitCount >>> 3) + 9L & 63L);
                int padlen = 65 - leftOver;
                update(finalState, padding, 0, padlen);
                update(finalState, bitCount);
                finalState.valid = true;
            }
            return encode(finalState.state, 16);
        }
       public String getHashString() {
            return toHex(getHash());
        }


        public static byte[] getHash(byte b[]) {
            MD5 md5 = new MD5();
            md5.update(b);
            return md5.getHash();
        }


        public static String getHashString(byte b[]) {
            MD5 md5 = new MD5();
            md5.update(b);
            return md5.getHashString();
        }


        public static byte[] getHash(InputStream in) throws IOException {
            MD5 md5 = new MD5();
            byte buffer[] = new byte[1024];
            int read;
            while((read = in.read(buffer)) != -1)
                md5.update(buffer, read);
            return md5.getHash();
        }


        public static String getHashString(InputStream in) throws IOException {
            MD5 md5 = new MD5();
            byte buffer[] = new byte[1024];
            int read;
            while((read = in.read(buffer)) != -1)
                md5.update(buffer, read);
            return md5.getHashString();
        }


        public static byte[] getHash(File f) throws IOException {
            return getHash(((InputStream) (new FileInputStream(f))));
        }


        public static String getHashString(File f) throws IOException {
            return getHashString(((InputStream) (new FileInputStream(f))));
        }


        public static byte[] getHash(String s) {
            MD5 md5 = new MD5();
            md5.update(s);
            return md5.getHash();
        }


        public static String getHashString(String s) {
            MD5 md5 = new MD5();
            md5.update(s);
            return md5.getHashString();
        }


        public static byte[] getHash(String s, String enc) throws
    UnsupportedEncodingException {
            MD5 md5 = new MD5();
            md5.update(s, enc);
            return md5.getHash();
        }


        public static String getHashString(String s, String enc) throws
    UnsupportedEncodingException {
            MD5 md5 = new MD5();
            md5.update(s, enc);
            return md5.getHashString();
        }


        public void reset() {
            workingState.reset();
            finalState.valid = false;
        }


        public String toString() {
            return getHashString();
        }


        private void update(MD5State state, byte buffer[], int offset, int
    length) {
            finalState.valid = false;
            if(length + offset > buffer.length)
                length = buffer.length - offset;
            int index = (int)(state.bitCount >>> 3) & 0x3f;
            state.bitCount += length << 3;
            int partlen = 64 - index;
            int i = 0;
            if(length >= partlen) {
                System.arraycopy(buffer, offset, state.buffer, index, partlen);
                transform(state, decode(state.buffer, 64, offset));
                for(i = partlen; i + 63 < length; i += 64)
                    transform(state, decode(buffer, 64, i));


                index = 0;
            }
            if(i < length) {
                int start = i;
                for(; i < length; i++)
                    state.buffer[(index + i) - start] = buffer[i + offset];


            }
        }


        public void update(byte buffer[], int offset, int length) {
            update(workingState, buffer, offset, length);
        }


        public void update(byte buffer[], int length) {
            update(buffer, 0, length);
        }


        public void update(byte buffer[]) {
            update(buffer, 0, buffer.length);
        }


        public void update(byte b) {
            byte buffer[] = new byte[1];
            buffer[0] = b;
            update(buffer, 1);
        }


        private void update(MD5State state, long l) {
            update(state, new byte[] {
                (byte)(int)(l >>> 0 & 255L), (byte)(int)(l >>> 8 & 255L), (byte
    )(int)(l >>> 16 & 255L), (byte)(int)(l >>> 24 & 255L), (byte)(int)(l >>> 32
    & 255L), (byte)(int)(l >>> 40 & 255L), (byte)(int)(l >>> 48 & 255L), (byte
    )(int)(l >>> 56 & 255L)
            }, 0, 8);
        }


        public void update(String s) {
            update(s.getBytes());
        }


        public void update(String s, String enc) throws
    UnsupportedEncodingException {
            update(s.getBytes(enc));
        }


        private static String toHex(byte hash[]) {
            StringBuffer buf = new StringBuffer(hash.length * 2);
            for(int i = 0; i < hash.length; i++)
            {
                int intVal = hash & 0xff;
                if(intVal < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(intVal));
            }


            return buf.toString();
        }


        private static int FF(int a, int b, int c, int d, int x, int s, int ac)
    {
            a += b & c | ~b & d;
            a += x;
            a += ac;
            a = a << s | a >>> 32 - s;
            return a + b;
        }


        private static int GG(int a, int b, int c, int d, int x, int s, int ac)
    {
            a += b & d | c & ~d;
            a += x;
            a += ac;
            a = a << s | a >>> 32 - s;
            return a + b;
        }


        private static int HH(int a, int b, int c, int d, int x, int s, int ac)
    {
            a += b ^ c ^ d;
            a += x;
            a += ac;
            a = a << s | a >>> 32 - s;
            return a + b;
        }


        private static int II(int a, int b, int c, int d, int x, int s, int ac)
    {
            a += c ^ (b | ~d);
            a += x;
            a += ac;
            a = a << s | a >>> 32 - s;
            return a + b;
        }


        private static byte[] encode(int input[], int len) {
            byte out[] = new byte[len];
            int j;
            int i = j = 0;
            for(; j < len; j += 4)
            {
                out[j] = (byte)(input & 0xff);
                out[j + 1] = (byte)(input >>> 8 & 0xff);
                out[j + 2] = (byte)(input >>> 16 & 0xff);
                out[j + 3] = (byte)(input >>> 24 & 0xff);
                i++;
            }


            return out;
        }


        private int[] decode(byte buffer[], int len, int offset) {
            int j;
            int i = j = 0;
            for(; j < len; j += 4)
            {
                decodeBuffer = buffer[j + offset] & 0xff | (buffer[j + 1 +
    offset] & 0xff) << 8 | (buffer[j + 2 + offset] & 0xff) << 16 | (buffer[j +
    3 + offset] & 0xff) << 24;
                i++;
            }


            return decodeBuffer;
        }


        private static void transform(MD5State state, int x[]) {
            int a = state.state[0];
            int b = state.state[1];
            int c = state.state[2];
            int d = state.state[3];
            a = FF(a, b, c, d, x[0], 7, 0xd76aa478);
            d = FF(d, a, b, c, x[1], 12, 0xe8c7b756);
            c = FF(c, d, a, b, x[2], 17, 0x242070db);
            b = FF(b, c, d, a, x[3], 22, 0xc1bdceee);
            a = FF(a, b, c, d, x[4], 7, 0xf57c0faf);
            d = FF(d, a, b, c, x[5], 12, 0x4787c62a);
            c = FF(c, d, a, b, x[6], 17, 0xa8304613);
            b = FF(b, c, d, a, x[7], 22, 0xfd469501);
            a = FF(a, b, c, d, x[8], 7, 0x698098d8);
            d = FF(d, a, b, c, x[9], 12, 0x8b44f7af);
            c = FF(c, d, a, b, x[10], 17, -42063);
            b = FF(b, c, d, a, x[11], 22, 0x895cd7be);
            a = FF(a, b, c, d, x[12], 7, 0x6b901122);
            d = FF(d, a, b, c, x[13], 12, 0xfd987193);
            c = FF(c, d, a, b, x[14], 17, 0xa679438e);
            b = FF(b, c, d, a, x[15], 22, 0x49b40821);
            a = GG(a, b, c, d, x[1], 5, 0xf61e2562);
            d = GG(d, a, b, c, x[6], 9, 0xc040b340);
            c = GG(c, d, a, b, x[11], 14, 0x265e5a51);
            b = GG(b, c, d, a, x[0], 20, 0xe9b6c7aa);
            a = GG(a, b, c, d, x[5], 5, 0xd62f105d);
            d = GG(d, a, b, c, x[10], 9, 0x2441453);
            c = GG(c, d, a, b, x[15], 14, 0xd8a1e681);
            b = GG(b, c, d, a, x[4], 20, 0xe7d3fbc8);
            a = GG(a, b, c, d, x[9], 5, 0x21e1cde6);
            d = GG(d, a, b, c, x[14], 9, 0xc33707d6);
            c = GG(c, d, a, b, x[3], 14, 0xf4d50d87);
            b = GG(b, c, d, a, x[8], 20, 0x455a14ed);
            a = GG(a, b, c, d, x[13], 5, 0xa9e3e905);
            d = GG(d, a, b, c, x[2], 9, 0xfcefa3f8);
            c = GG(c, d, a, b, x[7], 14, 0x676f02d9);
            b = GG(b, c, d, a, x[12], 20, 0x8d2a4c8a);
            a = HH(a, b, c, d, x[5], 4, 0xfffa3942);
            d = HH(d, a, b, c, x[8], 11, 0x8771f681);
            c = HH(c, d, a, b, x[11], 16, 0x6d9d6122);
            b = HH(b, c, d, a, x[14], 23, 0xfde5380c);
            a = HH(a, b, c, d, x[1], 4, 0xa4beea44);
            d = HH(d, a, b, c, x[4], 11, 0x4bdecfa9);
            c = HH(c, d, a, b, x[7], 16, 0xf6bb4b60);
            b = HH(b, c, d, a, x[10], 23, 0xbebfbc70);
            a = HH(a, b, c, d, x[13], 4, 0x289b7ec6);
            d = HH(d, a, b, c, x[0], 11, 0xeaa127fa);
            c = HH(c, d, a, b, x[3], 16, 0xd4ef3085);
            b = HH(b, c, d, a, x[6], 23, 0x4881d05);
            a = HH(a, b, c, d, x[9], 4, 0xd9d4d039);
            d = HH(d, a, b, c, x[12], 11, 0xe6db99e5);
            c = HH(c, d, a, b, x[15], 16, 0x1fa27cf8);
            b = HH(b, c, d, a, x[2], 23, 0xc4ac5665);
            a = II(a, b, c, d, x[0], 6, 0xf4292244);
            d = II(d, a, b, c, x[7], 10, 0x432aff97);
            c = II(c, d, a, b, x[14], 15, 0xab9423a7);
            b = II(b, c, d, a, x[5], 21, 0xfc93a039);
            a = II(a, b, c, d, x[12], 6, 0x655b59c3);
            d = II(d, a, b, c, x[3], 10, 0x8f0ccc92);
            c = II(c, d, a, b, x[10], 15, 0xffeff47d);
            b = II(b, c, d, a, x[1], 21, 0x85845dd1);
            a = II(a, b, c, d, x[8], 6, 0x6fa87e4f);
            d = II(d, a, b, c, x[15], 10, 0xfe2ce6e0);
            c = II(c, d, a, b, x[6], 15, 0xa3014314);
            b = II(b, c, d, a, x[13], 21, 0x4e0811a1);
            a = II(a, b, c, d, x[4], 6, 0xf7537e82);
            d = II(d, a, b, c, x[11], 10, 0xbd3af235);
            c = II(c, d, a, b, x[2], 15, 0x2ad7d2bb);
            b = II(b, c, d, a, x[9], 21, 0xeb86d391);
            state.state[0] += a;
            state.state[1] += b;
            state.state[2] += c;
            state.state[3] += d;
        }
        private MD5State workingState;
        private MD5State finalState;
        private int decodeBuffer[];
        private static final byte padding[] = {
            -128, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0
        };
    }


    ftw
  4. KısayolKısayol reportŞikayet pmÖzel Mesaj
    cukurova
    cukurova's avatar
    Kayıt Tarihi: 21/Aralık/2003
    Erkek

    Güzel yapmışsında, alıntı yaptığın yazı çok kötü abi, ben hiçbir şey bilmesem hashing burdan öğrenmem imkansız."Hashing denilen sey hash üretme islemidir. Puha bu mudur yane diyen cok olmustur herhalde.Belli bir stringden(text) belli bir algoritma ile belli uzunlukda bir String elde etmeye yarar.Fakat her stringden farkli bir hash olusur. Ayri stringden ayni hashler OLUSAMAZ (diyorlarki 2^128 de 1 ihtimal falan)" Hala anlamadım :))


    Hash algoritmaları , herhangi bir datayı alıp bunu bir fonksiyon algoritmasından (MD5,SHA,Panama...)  geçirir ve sonuç olarak size anlamsız bir (genelde hexeminal) bir kod verir.Bu kod, datanızın parmak izi gibidir ve bir benzeri yoktur (ispatlanamadı!). Veriyi şifrelemez, sadece onun parmak izini alır.
    Hash algoritmaları tek yönlü bir fonksiyondur.Yani fonksiyonun tersi yoktur ve "ters mühendisliğe" elverişli değildir. Bu fizikte yanma olayına benzer, kağıdı yakarsanız kül elde edersiniz.Ama külü tekrar kağıda çeviremezsiniz, sadece onun bir kağıda ait kül olduğunu tahmin edersiniz ama asla yaktığınız kağıdın şeklini bilemezsiniz.

  5. KısayolKısayol reportŞikayet pmÖzel Mesaj
    gambit
    gambit's avatar
    Kayıt Tarihi: 25/Ağustos/2005
    Erkek

    hocam idare et artık ne yapalım :)


    olacak o kadar adam kodda attırmış tı oraya bende ondan direk olarak onu aldım


    yaa ne yapacaksın kardeş o yazdığına bende çok güldüm ama ne yapalım en azından arkadaşlar bi fikir sahibi olsun diye ekledim


    kusura bakmayın


     


    MCP MCSA 2003 MCSE 2003
  6. KısayolKısayol reportŞikayet pmÖzel Mesaj
    gambit
    gambit's avatar
    Kayıt Tarihi: 25/Ağustos/2005
    Erkek

    valla arkadaşlar haklısınız gündüz gözü ve de ayık kafa ile okuyunca gerçekten de adamın saçmaladığının biraz farkına vardım :)


    biraz daha düzenli bir şeyler hazırlayacam


    MCP MCSA 2003 MCSE 2003
  7. KısayolKısayol reportŞikayet pmÖzel Mesaj
    cukurova
    cukurova's avatar
    Kayıt Tarihi: 21/Aralık/2003
    Erkek
    gambit bunu yazdı:



    valla arkadaşlar haklısınız gündüz gözü ve de ayık kafa ile okuyunca gerçekten de adamın saçmaladığının biraz farkına vardım :)


    biraz daha düzenli bir şeyler hazırlayacam




    Boşver kardeş olur böyle şeyler sıkma canını, yeterki amaçın iyi olsun.
    Bundan sonraki yazılarında örnek kodlar yerine işin mantığı verirsen daha yararlı olur kanatındeyim.
  8. KısayolKısayol reportŞikayet pmÖzel Mesaj
    ir2
    ir2's avatar
    Bilgi/Destek Madalyası Developer Madalyası
    Kayıt Tarihi: 10/Mayıs/2003
    Erkek

    md5 için vbasic modülü;
    'CalculateMD5("pipi") şeklinde kullanılcak


    Option Explicit


    Private lngTrack As Long
    Private arrLongConversion(4) As Long
    Private arrSplit64(63) As Byte


    Private Const OFFSET_4 = 4294967296#
    Private Const MAXINT_4 = 2147483647


     


    Private Const S11 = 7
    Private Const S12 = 12
    Private Const S13 = 17
    Private Const S14 = 22
    Private Const S21 = 5
    Private Const S22 = 9
    Private Const S23 = 14
    Private Const S24 = 20
    Private Const S31 = 4
    Private Const S32 = 11
    Private Const S33 = 16
    Private Const S34 = 23
    Private Const S41 = 6
    Private Const S42 = 10
    Private Const S43 = 15
    Private Const S44 = 21


    Private Function MD5Round(strRound As String, a As Long, b As Long, C As Long, d As Long, X As Long, S As Long, ac As Long) As Long


        Select Case strRound
       
            Case Is = "FF"
                a = MD5LongAdd4(a, (b And C) Or (Not (b) And d), X, ac)
                a = MD5Rotate(a, S)
                a = MD5LongAdd(a, b)
           
            Case Is = "GG"
                a = MD5LongAdd4(a, (b And d) Or (C And Not (d)), X, ac)
                a = MD5Rotate(a, S)
                a = MD5LongAdd(a, b)
               
            Case Is = "HH"
                a = MD5LongAdd4(a, b Xor C Xor d, X, ac)
                a = MD5Rotate(a, S)
                a = MD5LongAdd(a, b)
               
            Case Is = "II"
                a = MD5LongAdd4(a, C Xor (b Or Not (d)), X, ac)
                a = MD5Rotate(a, S)
                a = MD5LongAdd(a, b)
               
        End Select
       
    End Function


    Private Function MD5Rotate(lngValue As Long, lngBits As Long) As Long
       
        Dim lngSign As Long
        Dim lngI As Long
       
        lngBits = (lngBits Mod 32)
       
        If lngBits = 0 Then MD5Rotate = lngValue: Exit Function
       
        For lngI = 1 To lngBits
            lngSign = lngValue And &HC0000000
            lngValue = (lngValue And &H3FFFFFFF) * 2
            lngValue = lngValue Or ((lngSign < 0) And 1) Or (CBool(lngSign And &H40000000) And &H80000000)
        Next
       
        MD5Rotate = lngValue


    End Function


    Private Function TRID() As String


        Dim sngNum As Single, lngnum As Long
        Dim strResult As String
      
        sngNum = Rnd(2147483648#)
        strResult = CStr(sngNum)
       
        strResult = Replace(strResult, "0.", "")
        strResult = Replace(strResult, ".", "")
        strResult = Replace(strResult, "E-", "")
       
        TRID = strResult


    End Function


    Private Function MD564Split(lngLength As Long, bytBuffer() As Byte) As String


        Dim lngBytesTotal As Long, lngBytesToAdd As Long
        Dim intLoop As Integer, intLoop2 As Integer, lngTrace As Long
        Dim intInnerLoop As Integer, intLoop3 As Integer
       
        lngBytesTotal = lngTrack Mod 64
        lngBytesToAdd = 64 - lngBytesTotal
        lngTrack = (lngTrack + lngLength)
       
        If lngLength >= lngBytesToAdd Then
            For intLoop = 0 To lngBytesToAdd - 1
                arrSplit64(lngBytesTotal + intLoop) = bytBuffer(intLoop)
            Next intLoop
           
            MD5Conversion arrSplit64
           
            lngTrace = (lngLength) Mod 64


            For intLoop2 = lngBytesToAdd To lngLength - intLoop - lngTrace Step 64
                For intInnerLoop = 0 To 63
                    arrSplit64(intInnerLoop) = bytBuffer(intLoop2 + intInnerLoop)
                Next intInnerLoop
               
                MD5Conversion arrSplit64
           
            Next intLoop2
           
            lngBytesTotal = 0
        Else
       
          intLoop2 = 0
       
        End If
       
        For intLoop3 = 0 To lngLength - intLoop2 - 1
           
            arrSplit64(lngBytesTotal + intLoop3) = bytBuffer(intLoop2 + intLoop3)
       
        Next intLoop3
        
    End Function


    Private Function MD5StringArray(strInput As String) As Byte()
       
        Dim intLoop As Integer
        Dim bytBuffer() As Byte
        ReDim bytBuffer(Len(strInput))
       
        For intLoop = 0 To Len(strInput) - 1
            bytBuffer(intLoop) = Asc(Mid(strInput, intLoop + 1, 1))
        Next intLoop
       
        MD5StringArray = bytBuffer
       
    End Function


    Private Sub MD5Conversion(bytBuffer() As Byte)


        Dim X(16) As Long, a As Long
        Dim b As Long, C As Long
        Dim d As Long
       
        a = arrLongConversion(1)
        b = arrLongConversion(2)
        C = arrLongConversion(3)
        d = arrLongConversion(4)
       
        MD5Decode 64, X, bytBuffer
       
        MD5Round "FF", a, b, C, d, X(0), S11, -680876936
        MD5Round "FF", d, a, b, C, X(1), S12, -389564586
        MD5Round "FF", C, d, a, b, X(2), S13, 606105819
        MD5Round "FF", b, C, d, a, X(3), S14, -1044525330
        MD5Round "FF", a, b, C, d, X(4), S11, -176418897
        MD5Round "FF", d, a, b, C, X(5), S12, 1200080426
        MD5Round "FF", C, d, a, b, X(6), S13, -1473231341
        MD5Round "FF", b, C, d, a, X(7), S14, -45705983
        MD5Round "FF", a, b, C, d, X(8), S11, 1770035416
        MD5Round "FF", d, a, b, C, X(9), S12, -1958414417
        MD5Round "FF", C, d, a, b, X(10), S13, -42063
        MD5Round "FF", b, C, d, a, X(11), S14, -1990404162
        MD5Round "FF", a, b, C, d, X(12), S11, 1804603682
        MD5Round "FF", d, a, b, C, X(13), S12, -40341101
        MD5Round "FF", C, d, a, b, X(14), S13, -1502002290
        MD5Round "FF", b, C, d, a, X(15), S14, 1236535329


        MD5Round "GG", a, b, C, d, X(1), S21, -165796510
        MD5Round "GG", d, a, b, C, X(6), S22, -1069501632
        MD5Round "GG", C, d, a, b, X(11), S23, 643717713
        MD5Round "GG", b, C, d, a, X(0), S24, -373897302
        MD5Round "GG", a, b, C, d, X(5), S21, -701558691
        MD5Round "GG", d, a, b, C, X(10), S22, 38016083
        MD5Round "GG", C, d, a, b, X(15), S23, -660478335
        MD5Round "GG", b, C, d, a, X(4), S24, -405537848
        MD5Round "GG", a, b, C, d, X(9), S21, 568446438
        MD5Round "GG", d, a, b, C, X(14), S22, -1019803690
        MD5Round "GG", C, d, a, b, X(3), S23, -187363961
        MD5Round "GG", b, C, d, a, X(8), S24, 1163531501
        MD5Round "GG", a, b, C, d, X(13), S21, -1444681467
        MD5Round "GG", d, a, b, C, X(2), S22, -51403784
        MD5Round "GG", C, d, a, b, X(7), S23, 1735328473
        MD5Round "GG", b, C, d, a, X(12), S24, -1926607734
     
        MD5Round "HH", a, b, C, d, X(5), S31, -378558
        MD5Round "HH", d, a, b, C, X(8), S32, -2022574463
        MD5Round "HH", C, d, a, b, X(11), S33, 1839030562
        MD5Round "HH", b, C, d, a, X(14), S34, -35309556
        MD5Round "HH", a, b, C, d, X(1), S31, -1530992060
        MD5Round "HH", d, a, b, C, X(4), S32, 1272893353
        MD5Round "HH", C, d, a, b, X(7), S33, -155497632
        MD5Round "HH", b, C, d, a, X(10), S34, -1094730640
        MD5Round "HH", a, b, C, d, X(13), S31, 681279174
        MD5Round "HH", d, a, b, C, X(0), S32, -358537222
        MD5Round "HH", C, d, a, b, X(3), S33, -722521979
        MD5Round "HH", b, C, d, a, X(6), S34, 76029189
        MD5Round "HH", a, b, C, d, X(9), S31, -640364487
        MD5Round "HH", d, a, b, C, X(12), S32, -421815835
        MD5Round "HH", C, d, a, b, X(15), S33, 530742520
        MD5Round "HH", b, C, d, a, X(2), S34, -995338651
     
        MD5Round "II", a, b, C, d, X(0), S41, -198630844
        MD5Round "II", d, a, b, C, X(7), S42, 1126891415
        MD5Round "II", C, d, a, b, X(14), S43, -1416354905
        MD5Round "II", b, C, d, a, X(5), S44, -57434055
        MD5Round "II", a, b, C, d, X(12), S41, 1700485571
        MD5Round "II", d, a, b, C, X(3), S42, -1894986606
        MD5Round "II", C, d, a, b, X(10), S43, -1051523
        MD5Round "II", b, C, d, a, X(1), S44, -2054922799
        MD5Round "II", a, b, C, d, X(8), S41, 1873313359
        MD5Round "II", d, a, b, C, X(15), S42, -30611744
        MD5Round "II", C, d, a, b, X(6), S43, -1560198380
        MD5Round "II", b, C, d, a, X(13), S44, 1309151649
        MD5Round "II", a, b, C, d, X(4), S41, -145523070
        MD5Round "II", d, a, b, C, X(11), S42, -1120210379
        MD5Round "II", C, d, a, b, X(2), S43, 718787259
        MD5Round "II", b, C, d, a, X(9), S44, -343485551
       
        arrLongConversion(1) = MD5LongAdd(arrLongConversion(1), a)
        arrLongConversion(2) = MD5LongAdd(arrLongConversion(2), b)
        arrLongConversion(3) = MD5LongAdd(arrLongConversion(3), C)
        arrLongConversion(4) = MD5LongAdd(arrLongConversion(4), d)
       
    End Sub


    Private Function MD5LongAdd(lngVal1 As Long, lngVal2 As Long) As Long
       
        Dim lngHighWord As Long
        Dim lngLowWord As Long
        Dim lngOverflow As Long


        lngLowWord = (lngVal1 And &HFFFF&) + (lngVal2 And &HFFFF&)
        lngOverflow = lngLowWord \ 65536
        lngHighWord = (((lngVal1 And &HFFFF0000) \ 65536) + ((lngVal2 And &HFFFF0000) \ 65536) + lngOverflow) And &HFFFF&
       
        MD5LongAdd = MD5LongConversion((lngHighWord * 65536#) + (lngLowWord And &HFFFF&))


    End Function


    Private Function MD5LongAdd4(lngVal1 As Long, lngVal2 As Long, lngVal3 As Long, lngVal4 As Long) As Long
       
        Dim lngHighWord As Long
        Dim lngLowWord As Long
        Dim lngOverflow As Long


        lngLowWord = (lngVal1 And &HFFFF&) + (lngVal2 And &HFFFF&) + (lngVal3 And &HFFFF&) + (lngVal4 And &HFFFF&)
        lngOverflow = lngLowWord \ 65536
        lngHighWord = (((lngVal1 And &HFFFF0000) \ 65536) + ((lngVal2 And &HFFFF0000) \ 65536) + ((lngVal3 And &HFFFF0000) \ 65536) + ((lngVal4 And &HFFFF0000) \ 65536) + lngOverflow) And &HFFFF&
        MD5LongAdd4 = MD5LongConversion((lngHighWord * 65536#) + (lngLowWord And &HFFFF&))


    End Function


    Private Sub MD5Decode(intLength As Integer, lngOutBuffer() As Long, bytInBuffer() As Byte)
       
        Dim intDblIndex As Integer
        Dim intByteIndex As Integer
        Dim dblSum As Double
       
        intDblIndex = 0
       
        For intByteIndex = 0 To intLength - 1 Step 4
           
            dblSum = bytInBuffer(intByteIndex) + bytInBuffer(intByteIndex + 1) * 256# + bytInBuffer(intByteIndex + 2) * 65536# + bytInBuffer(intByteIndex + 3) * 16777216#
            lngOutBuffer(intDblIndex) = MD5LongConversion(dblSum)
            intDblIndex = (intDblIndex + 1)
       
        Next intByteIndex


    End Sub


    Private Function MD5LongConversion(dblValue As Double) As Long
       
        If dblValue < 0 Or dblValue >= OFFSET_4 Then Error 6
           
        If dblValue <= MAXINT_4 Then
            MD5LongConversion = dblValue
        Else
            MD5LongConversion = dblValue - OFFSET_4
        End If
           
    End Function


    Private Sub MD5Finish()
       
        Dim dblBits As Double
        Dim arrPadding(72) As Byte
        Dim lngBytesBuffered As Long
       
        arrPadding(0) = &H80
       
        dblBits = lngTrack * 8
       
        lngBytesBuffered = lngTrack Mod 64
       
        If lngBytesBuffered <= 56 Then
            MD564Split (56 - lngBytesBuffered), arrPadding
        Else
            MD564Split (120 - lngTrack), arrPadding
        End If
       
       
        arrPadding(0) = MD5LongConversion(dblBits) And &HFF&
        arrPadding(1) = MD5LongConversion(dblBits) \ 256 And &HFF&
        arrPadding(2) = MD5LongConversion(dblBits) \ 65536 And &HFF&
        arrPadding(3) = MD5LongConversion(dblBits) \ 16777216 And &HFF&
        arrPadding(4) = 0
        arrPadding(5) = 0
        arrPadding(6) = 0
        arrPadding(7) = 0
       
        MD564Split 8, arrPadding
       
    End Sub


    Private Function MD5StringChange(lngnum As Long) As String
           
            Dim bytA As Byte
            Dim bytB As Byte
            Dim bytC As Byte
            Dim bytD As Byte
           
            bytA = lngnum And &HFF&
            If bytA < 16 Then
                MD5StringChange = "0" & Hex(bytA)
            Else
                MD5StringChange = Hex(bytA)
            End If
                  
            bytB = (lngnum And &HFF00&) \ 256
            If bytB < 16 Then
                MD5StringChange = MD5StringChange & "0" & Hex(bytB)
            Else
                MD5StringChange = MD5StringChange & Hex(bytB)
            End If
           
            bytC = (lngnum And &HFF0000) \ 65536
            If bytC < 16 Then
                MD5StringChange = MD5StringChange & "0" & Hex(bytC)
            Else
                MD5StringChange = MD5StringChange & Hex(bytC)
            End If
          
            If lngnum < 0 Then
                bytD = ((lngnum And &H7F000000) \ 16777216) Or &H80&
            Else
                bytD = (lngnum And &HFF000000) \ 16777216
            End If
           
            If bytD < 16 Then
                MD5StringChange = MD5StringChange & "0" & Hex(bytD)
            Else
                MD5StringChange = MD5StringChange & Hex(bytD)
            End If


    End Function


    Private Function MD5Value() As String


        MD5Value = LCase(MD5StringChange(arrLongConversion(1)) & MD5StringChange(arrLongConversion(2)) & MD5StringChange(arrLongConversion(3)) & MD5StringChange(arrLongConversion(4)))


    End Function


    Public Function CalculateMD5(strMessage As String) As String


        Dim bytBuffer() As Byte
       
        bytBuffer = MD5StringArray(strMessage)
       
        MD5Start
        MD564Split Len(strMessage), bytBuffer
        MD5Finish
       
        CalculateMD5 = MD5Value
       
    End Function


    Private Sub MD5Start()


        lngTrack = 0
        arrLongConversion(1) = MD5LongConversion(1732584193#)
        arrLongConversion(2) = MD5LongConversion(4023233417#)
        arrLongConversion(3) = MD5LongConversion(2562383102#)
        arrLongConversion(4) = MD5LongConversion(271733878#)
       
    End Sub

Toplam Hit: 12718 Toplam Mesaj: 8