Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ICSharpCode.SharpZipLib/Encryption/PkzipClassic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ public override byte[] Key
public override void GenerateKey()
{
key_ = new byte[12];
var rnd = new Random();
rnd.NextBytes(key_);
var rng = new RNGCryptoServiceProvider();
rng.GetBytes(key_);
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3713,8 +3713,10 @@ private static void CheckClassicPassword(CryptoStream classicCryptoStream, ZipEn
private static void WriteEncryptionHeader(Stream stream, long crcValue)
{
byte[] cryptBuffer = new byte[ZipConstants.CryptoHeaderSize];
var rnd = new Random();
rnd.NextBytes(cryptBuffer);
using (var rng = new RNGCryptoServiceProvider())
{
rng.GetBytes(cryptBuffer);
}
cryptBuffer[11] = (byte)(crcValue >> 24);
stream.Write(cryptBuffer, 0, cryptBuffer.Length);
}
Expand Down
8 changes: 6 additions & 2 deletions src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;

namespace ICSharpCode.SharpZipLib.Zip
{
Expand Down Expand Up @@ -627,8 +628,11 @@ private void WriteEncryptionHeader(long crcValue)
InitializePassword(Password);

byte[] cryptBuffer = new byte[ZipConstants.CryptoHeaderSize];
var rnd = new Random();
rnd.NextBytes(cryptBuffer);
using (var rng = new RNGCryptoServiceProvider())
{
rng.GetBytes(cryptBuffer);
}

cryptBuffer[11] = (byte)(crcValue >> 24);

EncryptBlock(cryptBuffer, 0, cryptBuffer.Length);
Expand Down