public static bool VerifyMemeData(byte[] input, out byte[] output, MemeKeyIndex keyIndex)
        {
            output = null;
            if (input.Length < 0x60)
            {
                return(false);
            }
            var memekey = new MemeKey(keyIndex);

            output = (byte[])input.Clone();

            var sigBuffer = new byte[0x60];

            Array.Copy(input, input.Length - 0x60, sigBuffer, 0, 0x60);
            sigBuffer = memekey.RsaPublic(sigBuffer);
            using (var sha1 = SHA1.Create())
                foreach (var orVal in new byte[] { 0, 0x80 })
                {
                    sigBuffer[0x0] |= orVal;
                    sigBuffer.CopyTo(output, output.Length - 0x60);
                    memekey.AesDecrypt(output).CopyTo(output, 0);
                    // Check for 8-byte equality.
                    if (BitConverter.ToUInt64(sha1.ComputeHash(output, 0, output.Length - 0x8), 0) ==
                        BitConverter.ToUInt64(output, output.Length - 0x8))
                    {
                        return(true);
                    }
                }
            output = null;
            return(false);
        }
Beispiel #2
0
        private static bool DecryptCompare(byte[] output, byte[] sigBuffer, MemeKey key, SHA1 sha1)
        {
            sigBuffer.CopyTo(output, output.Length - 0x60);
            key.AesDecrypt(output).CopyTo(output, 0);
            // Check for 8-byte equality.
            var hash     = sha1.ComputeHash(output, 0, output.Length - 0x8);
            var computed = BitConverter.ToUInt64(hash, 0);
            var existing = BitConverter.ToUInt64(output, output.Length - 0x8);

            return(computed == existing);
        }