Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SecureRandom instead of Random to implement a cryptographically s… #448

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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