Browse Source

Fixed multiple crypto bugs.

master
Teknikode 2 years ago
parent
commit
86fe419389

+ 1
- 1
Utilities/Utilities/Cryptography/AesCounterManaged.cs 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);
}

+ 1
- 1
Utilities/Utilities/Cryptography/AesCounterMode.cs 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;
}

+ 4
- 5
Utilities/Utilities/Cryptography/AesCounterStream.cs 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);

+ 1
- 1
Utilities/Utilities/Cryptography/SHA256.cs 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);
}


Loading…
Cancel
Save