Files
2026-06-04 11:42:34 +02:00

186 lines
4.7 KiB
C#

using System;
using System.Security.Cryptography;
namespace ICSharpCode.SharpZipLib.Encryption
{
// Token: 0x02000026 RID: 38
internal class ZipAESTransform : ICryptoTransform, IDisposable
{
// Token: 0x06000105 RID: 261 RVA: 0x00008134 File Offset: 0x00007134
public ZipAESTransform(string key, byte[] saltBytes, int blockSize, bool writeMode)
{
if (blockSize != 16 && blockSize != 32)
{
throw new Exception("Invalid blocksize " + blockSize + ". Must be 16 or 32.");
}
if (saltBytes.Length != blockSize / 2)
{
throw new Exception(string.Concat(new object[]
{
"Invalid salt len. Must be ",
blockSize / 2,
" for blocksize ",
blockSize
}));
}
this._blockSize = blockSize;
this._encryptBuffer = new byte[this._blockSize];
this._encrPos = 16;
Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(key, saltBytes, 1000);
RijndaelManaged rijndaelManaged = new RijndaelManaged();
rijndaelManaged.Mode = CipherMode.ECB;
this._counterNonce = new byte[this._blockSize];
byte[] bytes = rfc2898DeriveBytes.GetBytes(this._blockSize);
byte[] bytes2 = rfc2898DeriveBytes.GetBytes(this._blockSize);
this._encryptor = rijndaelManaged.CreateEncryptor(bytes, bytes2);
this._pwdVerifier = rfc2898DeriveBytes.GetBytes(2);
this._hmacsha1 = new HMACSHA1(bytes2);
this._writeMode = writeMode;
}
// Token: 0x06000106 RID: 262 RVA: 0x00008248 File Offset: 0x00007248
public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
if (!this._writeMode)
{
this._hmacsha1.TransformBlock(inputBuffer, inputOffset, inputCount, inputBuffer, inputOffset);
}
for (int i = 0; i < inputCount; i++)
{
if (this._encrPos == 16)
{
int num = 0;
for (;;)
{
byte[] counterNonce = this._counterNonce;
int num2 = num;
if ((counterNonce[num2] += 1) != 0)
{
break;
}
num++;
}
this._encryptor.TransformBlock(this._counterNonce, 0, this._blockSize, this._encryptBuffer, 0);
this._encrPos = 0;
}
outputBuffer[i + outputOffset] = inputBuffer[i + inputOffset] ^ this._encryptBuffer[this._encrPos++];
}
if (this._writeMode)
{
this._hmacsha1.TransformBlock(outputBuffer, outputOffset, inputCount, outputBuffer, outputOffset);
}
return inputCount;
}
// Token: 0x1700002F RID: 47
// (get) Token: 0x06000107 RID: 263 RVA: 0x0000831C File Offset: 0x0000731C
public byte[] PwdVerifier
{
get
{
return this._pwdVerifier;
}
}
// Token: 0x06000108 RID: 264 RVA: 0x00008324 File Offset: 0x00007324
public byte[] GetAuthCode()
{
if (!this._finalised)
{
byte[] array = new byte[0];
this._hmacsha1.TransformFinalBlock(array, 0, 0);
this._finalised = true;
}
return this._hmacsha1.Hash;
}
// Token: 0x06000109 RID: 265 RVA: 0x00008361 File Offset: 0x00007361
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
throw new NotImplementedException("ZipAESTransform.TransformFinalBlock");
}
// Token: 0x17000030 RID: 48
// (get) Token: 0x0600010A RID: 266 RVA: 0x0000836D File Offset: 0x0000736D
public int InputBlockSize
{
get
{
return this._blockSize;
}
}
// Token: 0x17000031 RID: 49
// (get) Token: 0x0600010B RID: 267 RVA: 0x00008375 File Offset: 0x00007375
public int OutputBlockSize
{
get
{
return this._blockSize;
}
}
// Token: 0x17000032 RID: 50
// (get) Token: 0x0600010C RID: 268 RVA: 0x0000837D File Offset: 0x0000737D
public bool CanTransformMultipleBlocks
{
get
{
return true;
}
}
// Token: 0x17000033 RID: 51
// (get) Token: 0x0600010D RID: 269 RVA: 0x00008380 File Offset: 0x00007380
public bool CanReuseTransform
{
get
{
return true;
}
}
// Token: 0x0600010E RID: 270 RVA: 0x00008383 File Offset: 0x00007383
public void Dispose()
{
this._encryptor.Dispose();
}
// Token: 0x04000093 RID: 147
private const int PWD_VER_LENGTH = 2;
// Token: 0x04000094 RID: 148
private const int KEY_ROUNDS = 1000;
// Token: 0x04000095 RID: 149
private const int ENCRYPT_BLOCK = 16;
// Token: 0x04000096 RID: 150
private int _blockSize;
// Token: 0x04000097 RID: 151
private ICryptoTransform _encryptor;
// Token: 0x04000098 RID: 152
private readonly byte[] _counterNonce;
// Token: 0x04000099 RID: 153
private byte[] _encryptBuffer;
// Token: 0x0400009A RID: 154
private int _encrPos;
// Token: 0x0400009B RID: 155
private byte[] _pwdVerifier;
// Token: 0x0400009C RID: 156
private HMACSHA1 _hmacsha1;
// Token: 0x0400009D RID: 157
private bool _finalised;
// Token: 0x0400009E RID: 158
private bool _writeMode;
}
}