private void encryptTitleKey() { commonKeyIndex = newKeyIndex; byte[] ckey = CommonKey.GetStandardKey(); byte[] iv = BitConverter.GetBytes(Shared.Swap(titleId)); Array.Resize(ref iv, 16); RijndaelManaged rm = new RijndaelManaged(); rm.Mode = CipherMode.CBC; rm.Padding = PaddingMode.None; rm.KeySize = 128; rm.BlockSize = 128; rm.Key = ckey; rm.IV = iv; ICryptoTransform encryptor = rm.CreateEncryptor(); MemoryStream ms = new MemoryStream(decryptedTitleKey); CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Read); cs.Read(encryptedTitleKey, 0, encryptedTitleKey.Length); cs.Dispose(); ms.Dispose(); encryptor.Dispose(); rm.Clear(); }
private void decryptTitleKey() { byte[] ckey; if (dsitik) { ckey = CommonKey.GetDSiKey(); } else { ckey = (commonKeyIndex == 0x01) ? CommonKey.GetKoreanKey() : CommonKey.GetStandardKey(); } byte[] iv = BitConverter.GetBytes(Shared.Swap(titleId)); Array.Resize(ref iv, 16); RijndaelManaged rm = new RijndaelManaged(); rm.Mode = CipherMode.CBC; rm.Padding = PaddingMode.None; rm.KeySize = 128; rm.BlockSize = 128; rm.Key = ckey; rm.IV = iv; ICryptoTransform decryptor = rm.CreateDecryptor(); MemoryStream ms = new MemoryStream(encryptedTitleKey); CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read); cs.Read(decryptedTitleKey, 0, decryptedTitleKey.Length); cs.Dispose(); ms.Dispose(); decryptor.Dispose(); rm.Clear(); }