Skip to content

Commit 8a9dcb9

Browse files
committed
Replace insecure obsolete method (new RNGCryptoServiceProvider()) with RandomNumberGenerator.Create() in PkzipClassic, ZipFile and ZipOutputStream.
1 parent b5b1b07 commit 8a9dcb9

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/ICSharpCode.SharpZipLib/Encryption/PkzipClassic.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ICSharpCode.SharpZipLib.Encryption
66
{
77
/// <summary>
88
/// PkzipClassic embodies the classic or original encryption facilities used in Pkzip archives.
9-
/// While it has been superceded by more recent and more powerful algorithms, its still in use and
9+
/// While it has been superseded by more recent and more powerful algorithms, its still in use and
1010
/// is viable for preventing casual snooping
1111
/// </summary>
1212
public abstract class PkzipClassic : SymmetricAlgorithm
@@ -444,7 +444,7 @@ public override byte[] Key
444444
public override void GenerateKey()
445445
{
446446
key_ = new byte[12];
447-
using (var rng = new RNGCryptoServiceProvider())
447+
using (var rng = RandomNumberGenerator.Create())
448448
{
449449
rng.GetBytes(key_);
450450
}

src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3781,7 +3781,7 @@ private static void CheckClassicPassword(CryptoStream classicCryptoStream, ZipEn
37813781
private static void WriteEncryptionHeader(Stream stream, long crcValue)
37823782
{
37833783
byte[] cryptBuffer = new byte[ZipConstants.CryptoHeaderSize];
3784-
using (var rng = new RNGCryptoServiceProvider())
3784+
using (var rng = RandomNumberGenerator.Create())
37853785
{
37863786
rng.GetBytes(cryptBuffer);
37873787
}

src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ private byte[] CreateZipCryptoHeader(long crcValue)
723723
InitializeZipCryptoPassword(Password);
724724

725725
byte[] cryptBuffer = new byte[ZipConstants.CryptoHeaderSize];
726-
using (var rng = new RNGCryptoServiceProvider())
726+
using (var rng = RandomNumberGenerator.Create())
727727
{
728728
rng.GetBytes(cryptBuffer);
729729
}
@@ -808,11 +808,11 @@ public override void Write(byte[] buffer, int offset, int count)
808808

809809
private void CopyAndEncrypt(byte[] buffer, int offset, int count)
810810
{
811-
const int CopyBufferSize = 4096;
812-
byte[] localBuffer = new byte[CopyBufferSize];
811+
const int copyBufferSize = 4096;
812+
byte[] localBuffer = new byte[copyBufferSize];
813813
while (count > 0)
814814
{
815-
int bufferCount = (count < CopyBufferSize) ? count : CopyBufferSize;
815+
int bufferCount = (count < copyBufferSize) ? count : copyBufferSize;
816816

817817
Array.Copy(buffer, offset, localBuffer, 0, bufferCount);
818818
EncryptBlock(localBuffer, 0, bufferCount);

0 commit comments

Comments
 (0)