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); }
public static bool VerifyMemeData(byte[] input, out byte[] output, MemeKeyIndex keyIndex) { if (input.Length < 0x60) { output = input; return(false); } var key = new MemeKey(keyIndex); output = (byte[])input.Clone(); var sigBuffer = key.RsaPublic(input.SliceEnd(input.Length - 0x60)); using var sha1 = SHA1.Create(); if (DecryptCompare(output, sigBuffer, key, sha1)) { return(true); } sigBuffer[0x0] |= 0x80; if (DecryptCompare(output, sigBuffer, key, sha1)) { return(true); } output = input; return(false); }