(NS2): use different encryption for keys shorter than 96 bytes.

This commit is contained in:
morkt
2016-09-29 11:30:01 +04:00
parent 0134583782
commit 37023024b7
2 changed files with 21 additions and 7 deletions

View File

@@ -75,10 +75,8 @@ namespace GameRes.Formats.NScripter
if (string.IsNullOrEmpty (password))
return null;
var key = Encoding.ASCII.GetBytes (password);
if (key.Length < 96)
throw new OperationCanceledException ("Password should be at least 96 characters long");
using (var input = new Ns2Stream (file, key))
using (var input = OpenEncryptedStream (file, key))
{
dir = ReadIndex (input);
if (null == dir)
@@ -132,10 +130,18 @@ namespace GameRes.Formats.NScripter
{
return arc.File.CreateStream (entry.Offset, entry.Size);
}
var encrypted = new Ns2Stream (arc.File, nsa_arc.Key);
var encrypted = OpenEncryptedStream (arc.File, nsa_arc.Key);
return new StreamRegion (encrypted, entry.Offset, entry.Size);
}
Stream OpenEncryptedStream (ArcView file, byte[] key)
{
if (key.Length < 96)
return new EncryptedViewStream (file, key);
else
return new Ns2Stream (file, key);
}
private string QueryPassword ()
{
var options = Query<NsaOptions> (arcStrings.ArcEncryptedNotice);
@@ -165,7 +171,7 @@ namespace GameRes.Formats.NScripter
{
byte[] m_key;
static readonly Cryptography.MD5 MD5 = new Cryptography.MD5();
readonly Cryptography.MD5 MD5 = new Cryptography.MD5();
const int BlockSize = 32;