private static byte[] ReverseCrypt(byte[] input) { if (input.Length != 0x80) { throw new ArgumentException("Invalid Memecrypto decryption byte[]!"); } using (var sha1 = Util.GetSHA1Provider()) { byte[] PubKeyDer = "307C300D06092A864886F70D0101010500036B003068026100B61E192091F90A8F76A6EAAA9A3CE58C863F39AE253F037816F5975854E07A9A456601E7C94C29759FE155C064EDDFA111443F81EF1A428CF6CD32F9DAC9D48E94CFB3F690120E8E6B9111ADDAF11E7C96208C37C0143FF2BF3D7E831141A9730203010001".ToByteArray(); byte[] enc = new byte[0x60]; Array.Copy(input, 0x20, enc, 0, 0x60); byte[] keybuf = new byte[PubKeyDer.Length + 0x20]; Array.Copy(PubKeyDer, keybuf, PubKeyDer.Length); Array.Copy(input, 0, keybuf, PubKeyDer.Length, 0x20); byte[] key = sha1.ComputeHash(keybuf).Take(0x10).ToArray(); byte[] RSA = RSAEncrypt(enc); var dec = MemeCryptoAESDecrypt(key, RSA); if (sha1.ComputeHash(dec).Take(0x8).SequenceEqual(dec.Skip(0x58))) { return(dec); } RSA[0] |= 0x80; dec = MemeCryptoAESDecrypt(key, RSA); if (sha1.ComputeHash(dec).Take(0x8).SequenceEqual(dec.Skip(0x58))) { return(dec); } } return(null); }
private static byte[] ReverseCrypt(byte[] input, int meme_ofs, int memeindex) { var output = (byte[])input.Clone(); var memekey = MemeKeys[memeindex]; using (var sha1 = Util.GetSHA1Provider()) { var enc = new byte[0x60]; Array.Copy(input, meme_ofs, enc, 0, 0x60); var keybuf = new byte[memekey.DER.Length + meme_ofs]; Array.Copy(memekey.DER, keybuf, memekey.DER.Length); if (meme_ofs > 0) { Array.Copy(input, 0, keybuf, memekey.DER.Length, meme_ofs); } var key = sha1.ComputeHash(keybuf).Take(0x10).ToArray(); var RSA = RSAEncrypt(enc, memeindex); MemeCryptoAESDecrypt(key, RSA).CopyTo(output, meme_ofs); if (sha1.ComputeHash(output, 0, meme_ofs + 0x58).Take(0x8).SequenceEqual(output.Skip(meme_ofs + 0x58).Take(0x8))) { return(output); } RSA[0] |= 0x80; MemeCryptoAESDecrypt(key, RSA).CopyTo(output, meme_ofs); if (sha1.ComputeHash(output, 0, meme_ofs + 0x58).Take(0x8).SequenceEqual(output.Skip(meme_ofs + 0x58).Take(0x8))) { return(output); } } return(null); }
public static byte[] SignMemeData(byte[] input) { if (input.Length < 0x60) { throw new ArgumentException("Bad Meme input!"); } byte[] PubKeyDer = "307C300D06092A864886F70D0101010500036B003068026100B61E192091F90A8F76A6EAAA9A3CE58C863F39AE253F037816F5975854E07A9A456601E7C94C29759FE155C064EDDFA111443F81EF1A428CF6CD32F9DAC9D48E94CFB3F690120E8E6B9111ADDAF11E7C96208C37C0143FF2BF3D7E831141A9730203010001".ToByteArray(); using (var sha1 = Util.GetSHA1Provider()) { byte[] key = sha1.ComputeHash(PubKeyDer.Concat(input.Take(input.Length - 0x60)).ToArray()).Take(0x10).ToArray(); byte[] output = (byte[])input.Clone(); Array.Copy(sha1.ComputeHash(input, 0, input.Length - 8), 0, output, output.Length - 8, 8); byte[] MemeCrypted = MemeCryptoAESEncrypt(key, output.Skip(output.Length - 0x60).ToArray()); MemeCrypted[0] &= 0x7F; var RSA = RSADecrypt(MemeCrypted); RSA.CopyTo(output, output.Length - 0x60); return(output); } }
public static byte[] SignMemeData(byte[] input) { if (input.Length < 0x60) { throw new ArgumentException("Bad Meme input!"); } const int memeindex = 3; using (var sha1 = Util.GetSHA1Provider()) { var key = sha1.ComputeHash(MemeKeys[memeindex].DER.Concat(input.Take(input.Length - 0x60)).ToArray()).Take(0x10).ToArray(); var output = (byte[])input.Clone(); Array.Copy(sha1.ComputeHash(input, 0, input.Length - 8), 0, output, output.Length - 8, 8); var MemeCrypted = MemeCryptoAESEncrypt(key, output.Skip(output.Length - 0x60).ToArray()); MemeCrypted[0] &= 0x7F; var RSA = RSADecrypt(MemeCrypted); RSA.CopyTo(output, output.Length - 0x60); return(output); } }