Example #1
0
 /// <summary>
 /// Decrypts and unpacks DS2's regulation BND4 from the specified path.
 /// </summary>
 public static BND4 DecryptDS2Regulation(string path)
 {
     byte[] bytes = File.ReadAllBytes(path);
     byte[] iv    = new byte[16];
     iv[0] = 0x80;
     Array.Copy(bytes, 0, iv, 1, 11);
     iv[15] = 1;
     byte[] input = new byte[bytes.Length - 32];
     Array.Copy(bytes, 32, input, 0, bytes.Length - 32);
     using (var ms = new MemoryStream(input))
     {
         byte[] decrypted = CryptographyUtility.DecryptAesCtr(ms, ds2RegulationKey, iv);
         return(BND4.Read(decrypted));
     }
 }
Example #2
0
        private void ReadCtr(Stream inputStream)
        {
            BigEndianBinaryReader reader = new BigEndianBinaryReader(inputStream, Encoding.ASCII, true);

            _iv[00] = 0x80;
            for (int i = 1; i <= 11; i++)
            {
                _iv[i] = reader.ReadByte();
            }
            _iv[12] = 0x00;
            _iv[13] = 0x00;
            _iv[14] = 0x00;
            _iv[15] = 0x01;
            inputStream.Seek(EncryptionIvCtrSize, SeekOrigin.Begin);
            byte[] encryptedData = reader.ReadBytes((int)inputStream.Length - EncryptionIvCtrSize);
            Data = CryptographyUtility.DecryptAesCtr(new MemoryStream(encryptedData), _key, _iv);
        }