mirror of
https://github.com/RoastSlav/quickdrop.git
synced 2026-01-06 06:29:57 -06:00
made the utility classes instantiable
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package org.rostislav.quickdrop.util;
|
||||
|
||||
public class DataValidator {
|
||||
private DataValidator() {
|
||||
// To prevent instantiation
|
||||
}
|
||||
|
||||
public static boolean validateObjects(Object... objs) {
|
||||
for (Object temp : objs) {
|
||||
if (temp != null) {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.rostislav.quickdrop.util;
|
||||
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -10,21 +14,15 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public class FileEncryptionUtils {
|
||||
private static final String ALGORITHM = "AES/CBC/PKCS5Padding";
|
||||
private static final int ITERATION_COUNT = 65536;
|
||||
private static final int KEY_LENGTH = 128;
|
||||
|
||||
private FileEncryptionUtils() {
|
||||
// To prevent instantiation
|
||||
}
|
||||
|
||||
public static SecretKey generateKeyFromPassword(String password, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, ITERATION_COUNT, KEY_LENGTH);
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
|
||||
|
||||
@@ -5,6 +5,9 @@ import org.rostislav.quickdrop.model.FileEntity;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
public class FileUtils {
|
||||
private FileUtils() {
|
||||
// To prevent instantiation
|
||||
}
|
||||
|
||||
public static String formatFileSize(long size) {
|
||||
String[] units = {"B", "KB", "MB", "GB", "TB"};
|
||||
@@ -17,6 +20,14 @@ public class FileUtils {
|
||||
return String.format("%.2f %s", sizeInUnits, units[unitIndex]);
|
||||
}
|
||||
|
||||
public static long bytesToMegabytes(long bytes) {
|
||||
return bytes / 1024 / 1024;
|
||||
}
|
||||
|
||||
public static long megabytesToBytes(long megabytes) {
|
||||
return megabytes * 1024 * 1024;
|
||||
}
|
||||
|
||||
public static String getDownloadLink(HttpServletRequest request, FileEntity fileEntity) {
|
||||
return request.getScheme() + "://" + request.getServerName() + "/file/" + fileEntity.uuid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user