Ejemplo n.º 1
0
        public static void EncryptDecrypt(Stream input, Stream output, byte[] key, out byte[] digest)
        {
            byte[] header = new byte[0x20];
            input.Read(header, 0, 0x20);
            output.Write(header, 0, 0x20);

            var length = BufferUtils.ToUInt32(header, 0x0c);

            var data = new byte[length - 0x20];

            input.Read(data, 0, data.Length);

            var hash = XeCrypt.XeCryptHmacSha(key, header, 0x10, 0x10);

            Array.Resize(ref hash, 0x10);

            digest = new byte[0x10];
            Buffer.BlockCopy(hash, 0, digest, 0, 0x10);

            // Decrypt the data
            var rc4 = XeCrypt.XeCryptRc4Key(hash);

            XeCrypt.XeCryptRc4Ecb(rc4, ref data, 0, data.Length);

            output.Write(data, 0, data.Length);
        }
Ejemplo n.º 2
0
        public void Decrypt(Stream output, byte[] key, out byte[] digest)
        {
            Stream.Seek(Origin, SeekOrigin.Begin);

            byte[] header = new byte[0x20];
            Stream.Read(header, 0, 0x20);
            output.Write(header, 0, 0x20);

            var data = new byte[length - 0x20];

            Stream.Read(data, 0, data.Length);

            var hash = XeCrypt.XeCryptHmacSha(key, header, 0x10, 0x10);

            Array.Resize(ref hash, 0x10);

            digest = new byte[0x10];
            Buffer.BlockCopy(hash, 0, digest, 0, 0x10);

            // Decrypt the data
            var rc4 = XeCrypt.XeCryptRc4Key(hash);

            XeCrypt.XeCryptRc4Ecb(rc4, ref data, 0, data.Length);

            output.Write(data, 0, data.Length);
        }
Ejemplo n.º 3
0
        public byte[] GetDigestKey(byte[] key)
        {
            Stream.Seek(Origin + 0x10, SeekOrigin.Begin);

            var hash = XeCrypt.XeCryptHmacSha(key, hmacSalt, 0, 0x10);

            Array.Resize(ref hash, 0x10);

            return(hash);
        }