Esempio n. 1
0
    public static String Decrypt(Byte[] mapKey, Byte[] encrypted)
    {
        Sha1 sha1 = new Sha1();

        Byte[] xorKey       = new Byte[encrypted.Length + 19];
        UInt32 xorKeyLength = 0;

        int counter = 0;

        while (xorKeyLength < encrypted.Length)
        {
            Byte[] counterStringBytes = Encoding.ASCII.GetBytes(counter.ToString());
            sha1.Add(counterStringBytes, 0, counterStringBytes.Length);
            sha1.Add(mapKey, 0, mapKey.Length);
            sha1.Add(sharedServerSecret, 0, sharedServerSecret.Length);
            sha1.Add(counterStringBytes, 0, counterStringBytes.Length);

            UInt32[] hash = sha1.Finish();

            xorKey.BigEndianSetUInt32(xorKeyLength + 0, hash[0]);
            xorKey.BigEndianSetUInt32(xorKeyLength + 4, hash[1]);
            xorKey.BigEndianSetUInt32(xorKeyLength + 8, hash[2]);
            xorKey.BigEndianSetUInt32(xorKeyLength + 12, hash[3]);
            xorKey.BigEndianSetUInt32(xorKeyLength + 16, hash[4]);
            xorKeyLength += 20;

            sha1.Reset();
            counter++;
        }

        Char[] decrypted = new Char[encrypted.Length];
        for (int i = 0; i < decrypted.Length; i++)
        {
            decrypted[i] = (Char)(xorKey[i] ^ encrypted[i]);
        }

        return(new String(decrypted));
    }