Changed SHA1Managed to SHA1CryptoServiceProvider

This commit is contained in:
Evan Dixon 2016-11-10 09:49:20 -06:00
parent f743b0a152
commit 9ab924ffe5

View file

@ -203,6 +203,9 @@ namespace PKHeX
{
if (input.Length != 0x80)
throw new ArgumentException("Invalid Memecrypto decryption byte[]!");
var sha1 = new SHA1CryptoServiceProvider();
byte[] PubKeyDer = "307C300D06092A864886F70D0101010500036B003068026100B61E192091F90A8F76A6EAAA9A3CE58C863F39AE253F037816F5975854E07A9A456601E7C94C29759FE155C064EDDFA111443F81EF1A428CF6CD32F9DAC9D48E94CFB3F690120E8E6B9111ADDAF11E7C96208C37C0143FF2BF3D7E831141A9730203010001".ToByteArray();
byte[] enc = new byte[0x60];
Array.Copy(input, 0x20, enc, 0, 0x60);
@ -210,15 +213,15 @@ namespace PKHeX
byte[] keybuf = new byte[PubKeyDer.Length + 0x20];
Array.Copy(PubKeyDer, keybuf, PubKeyDer.Length);
Array.Copy(input, 0, keybuf, PubKeyDer.Length, 0x20);
byte[] key = new SHA1Managed().ComputeHash(keybuf).Take(0x10).ToArray();
byte[] key = sha1.ComputeHash(keybuf).Take(0x10).ToArray();
byte[] RSA = RSAEncrypt(enc);
var dec = MemeCryptoAESDecrypt(key, RSA);
if (new SHA1Managed().ComputeHash(dec).Take(0x8).SequenceEqual(dec.Skip(0x58)))
if (sha1.ComputeHash(dec).Take(0x8).SequenceEqual(dec.Skip(0x58)))
return dec;
RSA[0] |= 0x80;
dec = MemeCryptoAESDecrypt(key, RSA);
if (new SHA1Managed().ComputeHash(dec).Take(0x8).SequenceEqual(dec.Skip(0x58)))
if (sha1.ComputeHash(dec).Take(0x8).SequenceEqual(dec.Skip(0x58)))
return dec;
return null;
}
@ -228,6 +231,8 @@ namespace PKHeX
if (sav7 == null || sav7.Length != 0x6BE00)
return null;
var sha1 = new SHA1CryptoServiceProvider();
byte[] outSav = (byte[])sav7.Clone();
byte[] CurSig = new byte[0x80];
@ -242,13 +247,13 @@ namespace PKHeX
byte[] keybuf = new byte[PubKeyDer.Length + 0x20];
Array.Copy(PubKeyDer, keybuf, PubKeyDer.Length);
Array.Copy(Hash, 0, keybuf, PubKeyDer.Length, 0x20);
byte[] key = new SHA1Managed().ComputeHash(keybuf).Take(0x10).ToArray();
byte[] key = sha1.ComputeHash(keybuf).Take(0x10).ToArray();
byte[] secret = ReverseCrypt(CurSig) ?? new byte[0x60];
byte[] secretWorkBuf = new byte[0x78];
Hash.CopyTo(secretWorkBuf, 0);
Array.Copy(secret, 0, secretWorkBuf, 0x20, 0x58);
Array.Copy(new SHA1Managed().ComputeHash(secretWorkBuf), 0, secret, 0x58, 8);
Array.Copy(sha1.ComputeHash(secretWorkBuf), 0, secret, 0x58, 8);
Hash.CopyTo(outSav, 0x6BB00);
byte[] MemeCrypted = MemeCryptoAESEncrypt(key, secret);