Skip to content

Commit

Permalink
Use SecureRandom instead of Random to implement a cryptographically s…
Browse files Browse the repository at this point in the history
…trong random number (#448)

Use SecureRandom instead of Random to implement a cryptographically strong random number
  • Loading branch information
PlayerA authored Jul 5, 2022
1 parent ce99554 commit 9c7bb74
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.security.SecureRandom;

abstract class AbstractModifyFileTask<T> extends AsyncZipTask<T> {

Expand All @@ -24,7 +24,7 @@ abstract class AbstractModifyFileTask<T> extends AsyncZipTask<T> {
}

File getTemporaryFile(String zipPathWithName) {
Random random = new Random();
SecureRandom random = new SecureRandom();
File tmpFile = new File(zipPathWithName + random.nextInt(10000));

while (tmpFile.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.security.SecureRandom;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
Expand Down Expand Up @@ -152,7 +152,7 @@ public void testExtractWithReadLengthGreaterThanButNotMultipleOf16WithZipCryptoA

@Test
public void testExtractWithRandomLengthWithAesAndDeflateCompression() throws IOException {
Random random = new Random();
SecureRandom random = new SecureRandom();
File createZipFile = createZipFile(CompressionMethod.DEFLATE, true, EncryptionMethod.AES, AesKeyStrength.KEY_STRENGTH_256, PASSWORD);
LocalFileHeader localFileHeader;
int readLen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import java.security.SecureRandom;

public class RandomInputStream extends InputStream {

private static final Random RANDOM = new Random();
private static final SecureRandom RANDOM = new SecureRandom();

private long remaining;
private boolean streamClosed;
Expand Down

0 comments on commit 9c7bb74

Please sign in to comment.