mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-22 23:15:20 +00:00
Style issue and access modifiers
This commit is contained in:
@@ -18,8 +18,7 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
}
|
||||
|
||||
private Options Options { get; set; }
|
||||
public string Password { get; set; }
|
||||
|
||||
public string Password { get; private set; }
|
||||
internal StreamingMode StreamingMode { get; private set; }
|
||||
|
||||
internal bool IsEncrypted { get; set; }
|
||||
@@ -182,7 +181,7 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
{
|
||||
ReadOnlySubStream ms
|
||||
= new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize);
|
||||
fh.PackedStream = new RarCryptoWrapper(ms, Password) { Salt = fh.Salt};
|
||||
fh.PackedStream = fh.Salt == null? (Stream) ms : new RarCryptoWrapper(ms, Password) { Salt = fh.Salt};
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -8,17 +8,17 @@ using System.Text;
|
||||
|
||||
namespace SharpCompress.Common.Rar
|
||||
{
|
||||
class RarRijndael : IDisposable
|
||||
internal class RarRijndael : IDisposable
|
||||
{
|
||||
private readonly string _password;
|
||||
private readonly byte[] _salt;
|
||||
private byte[] _aesInitializationVector;
|
||||
private Rijndael _rijndael;
|
||||
private readonly string password;
|
||||
private readonly byte[] salt;
|
||||
private byte[] aesInitializationVector;
|
||||
private Rijndael rijndael;
|
||||
|
||||
private RarRijndael(string password, byte[] salt)
|
||||
{
|
||||
_password = password;
|
||||
_salt = salt;
|
||||
this.password = password;
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
internal const int CryptoBlockSize = 16;
|
||||
@@ -26,19 +26,19 @@ namespace SharpCompress.Common.Rar
|
||||
private void Initialize()
|
||||
{
|
||||
|
||||
_rijndael = new RijndaelManaged() { Padding = PaddingMode.None };
|
||||
_aesInitializationVector = new byte[CryptoBlockSize];
|
||||
int rawLength = 2 * _password.Length;
|
||||
rijndael = new RijndaelManaged() { Padding = PaddingMode.None };
|
||||
aesInitializationVector = new byte[CryptoBlockSize];
|
||||
int rawLength = 2 * this.password.Length;
|
||||
byte[] rawPassword = new byte[rawLength + 8];
|
||||
byte[] passwordBytes = Encoding.UTF8.GetBytes(_password);
|
||||
for (int i = 0; i < _password.Length; i++)
|
||||
byte[] passwordBytes = Encoding.UTF8.GetBytes(this.password);
|
||||
for (int i = 0; i < this.password.Length; i++)
|
||||
{
|
||||
rawPassword[i * 2] = passwordBytes[i];
|
||||
rawPassword[i * 2 + 1] = 0;
|
||||
}
|
||||
for (int i = 0; i < _salt.Length; i++)
|
||||
for (int i = 0; i < salt.Length; i++)
|
||||
{
|
||||
rawPassword[i + rawLength] = _salt[i];
|
||||
rawPassword[i + rawLength] = salt[i];
|
||||
}
|
||||
|
||||
SHA1 sha = new SHA1CryptoServiceProvider();
|
||||
@@ -56,7 +56,7 @@ namespace SharpCompress.Common.Rar
|
||||
if (i % (noOfRounds / CryptoBlockSize) == 0)
|
||||
{
|
||||
digest = sha.ComputeHash(bytes.ToArray());
|
||||
_aesInitializationVector[i / (noOfRounds / CryptoBlockSize)] = digest[19];
|
||||
aesInitializationVector[i / (noOfRounds / CryptoBlockSize)] = digest[19];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,9 +72,9 @@ namespace SharpCompress.Common.Rar
|
||||
(uint)((digest[i * 4 + 2] * 0x100) & 0xff00) |
|
||||
(uint)(digest[i * 4 + 3] & 0xff)) >> (j * 8));
|
||||
|
||||
_rijndael.IV = new byte[CryptoBlockSize];
|
||||
_rijndael.Key = aesKey;
|
||||
_rijndael.BlockSize = CryptoBlockSize * 8;
|
||||
rijndael.IV = new byte[CryptoBlockSize];
|
||||
rijndael.Key = aesKey;
|
||||
rijndael.BlockSize = CryptoBlockSize * 8;
|
||||
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace SharpCompress.Common.Rar
|
||||
{
|
||||
var plainText = new byte[CryptoBlockSize];
|
||||
var decryptedBytes = new List<byte>();
|
||||
var decryptor = _rijndael.CreateDecryptor();
|
||||
var decryptor = rijndael.CreateDecryptor();
|
||||
using (var msDecrypt = new MemoryStream(cipherText))
|
||||
{
|
||||
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
|
||||
@@ -99,16 +99,16 @@ namespace SharpCompress.Common.Rar
|
||||
}
|
||||
|
||||
for (int j = 0; j < plainText.Length; j++)
|
||||
decryptedBytes.Add((byte)(plainText[j] ^ _aesInitializationVector[j % 16])); //32:114, 33:101
|
||||
decryptedBytes.Add((byte)(plainText[j] ^ aesInitializationVector[j % 16])); //32:114, 33:101
|
||||
|
||||
for (int j = 0; j < _aesInitializationVector.Length; j++)
|
||||
_aesInitializationVector[j] = cipherText[j];
|
||||
for (int j = 0; j < aesInitializationVector.Length; j++)
|
||||
aesInitializationVector[j] = cipherText[j];
|
||||
return decryptedBytes.ToArray();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_rijndael.Dispose();
|
||||
rijndael.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user