1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Fixed multiple crypto bugs.

This commit is contained in:
Uncled1023 2017-06-09 10:41:00 -07:00
parent a9aff56a27
commit 86fe419389
4 changed files with 7 additions and 8 deletions

View File

@ -121,7 +121,7 @@ namespace Teknik.Utilities.Cryptography
}
public static byte[] CreateKey(string password, byte[] iv, int keySize = 256)
{
const int Iterations = 300;
const int Iterations = 5000;
var keyGenerator = new Rfc2898DeriveBytes(password, iv, Iterations);
return keyGenerator.GetBytes(keySize / 8);
}

View File

@ -84,7 +84,7 @@ namespace Teknik.Utilities.Cryptography
}
set
{
if (value > 0 && value < _EncryptedCounter.Length)
if (value >= 0 && value < _EncryptedCounter.Length)
{
_CounterPosition = value;
}

View File

@ -52,14 +52,14 @@ namespace Teknik.Utilities.Cryptography
if (bytesRead > 0)
{
// Process the read buffer
processed = _Cipher.TransformBlock(readBuf, 0, bytesRead, buffer, 0);
processed = _Cipher.TransformBlock(readBuf, 0, bytesRead, buffer, offset);
}
// Do we have more?
if (processed < bytesRead)
{
// Finalize the cipher
byte[] finalBuf = _Cipher.TransformFinalBlock(readBuf, processed, bytesRead);
byte[] finalBuf = _Cipher.TransformFinalBlock(readBuf, processed + offset, bytesRead);
finalBuf.CopyTo(buffer, processed);
processed += finalBuf.Length;
}
@ -77,15 +77,14 @@ namespace Teknik.Utilities.Cryptography
byte[] output = new byte[count];
// Process the buffer
int processed = _Cipher.TransformBlock(buffer, 0, count, output, 0);
int processed = _Cipher.TransformBlock(buffer, offset, count, output, 0);
// Do we have more?
if (processed < count)
{
// Finalize the cipher
byte[] finalBuf = _Cipher.TransformFinalBlock(buffer, processed, count);
byte[] finalBuf = _Cipher.TransformFinalBlock(buffer, processed + offset, count);
finalBuf.CopyTo(output, processed);
processed += finalBuf.Length;
}
_Inner.Write(output, 0, count);

View File

@ -12,7 +12,7 @@ namespace Teknik.Utilities.Cryptography
{
public static string Hash(string value)
{
byte[] valueBytes = Encoding.Unicode.GetBytes(value);
byte[] valueBytes = Encoding.UTF8.GetBytes(value);
return Hash(valueBytes);
}