private static Modulus LoadKey(string file, ushort header, bool loadModulus, bool loadEncKey, bool loadDecKey, bool loadXOrKey) { var key = new Modulus(); using (var f = File.OpenRead(file)) { var fheader = Serializer.Deserialize <ENCDEC_FILEHEADER>(f); if (fheader.sFileHeader != header) { throw new Exception("Invalid file format"); } var Size = 6; Size += loadModulus ? 16 : 0; Size += loadEncKey ? 16 : 0; Size += loadDecKey ? 16 : 0; Size += loadXOrKey ? 16 : 0; if (fheader.Size != Size) { throw new ArgumentException("Invalid file size"); } var temp = new byte[16]; if (loadModulus) { f.Read(temp, 0, 16); for (var i = 0; i < 4; i++) { key.modulus[i] = s_saveLoadXor[i] ^ BitConverter.ToUInt32(temp, i * 4); } } if (loadEncKey) { f.Read(temp, 0, 16); for (var i = 0; i < 4; i++) { key.encryptionKey[i] = s_saveLoadXor[i] ^ BitConverter.ToUInt32(temp, i * 4); } } if (loadDecKey) { f.Read(temp, 0, 16); for (var i = 0; i < 4; i++) { key.decryptionKey[i] = s_saveLoadXor[i] ^ BitConverter.ToUInt32(temp, i * 4); } } if (loadXOrKey) { f.Read(temp, 0, 16); for (var i = 0; i < 4; i++) { key.xor[i] = s_saveLoadXor[i] ^ BitConverter.ToUInt32(temp, i * 4); } } } return(key); }
public static void LoadDecryptionKey(string file) { s_dec = LoadKey(file, 4370, true, false, true, true); }