Skip to content
Open
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
23 changes: 18 additions & 5 deletions modules/org.jkiss.utils/src/org/jkiss/utils/SecurityUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,8 @@
*/
public class SecurityUtils {

public static String ECRYPTION_ALGORYTHM = "MD5";
public static String HASH_ALGORYTHM_MD5 = "MD5";
public static String HASH_ALGORYTHM_SHA = "SHA-256";

private static java.util.Random random;
private static java.util.Random secureRand;
Expand Down Expand Up @@ -80,7 +81,7 @@

byte[] array;
try {
MessageDigest md5 = MessageDigest.getInstance(ECRYPTION_ALGORYTHM);
MessageDigest md5 = MessageDigest.getInstance(HASH_ALGORYTHM_MD5);
md5.update(sb.toString().getBytes(StandardCharsets.UTF_8));
array = md5.digest();
} catch (NoSuchAlgorithmException e) {
Expand Down Expand Up @@ -132,7 +133,7 @@
userPassword = "";
}
MessageDigest md5 =
MessageDigest.getInstance(ECRYPTION_ALGORYTHM);
MessageDigest.getInstance(HASH_ALGORYTHM_MD5);
md5.update(userAlias.getBytes(StandardCharsets.UTF_8));

return CommonUtils.toHexString(md5.digest(userPassword.getBytes(StandardCharsets.UTF_8)));
Expand All @@ -141,11 +142,23 @@
}
}

public static String makeDigestSha(
String userPassword) {
try {
MessageDigest sha =
MessageDigest.getInstance(HASH_ALGORYTHM_SHA);

return CommonUtils.toHexString(sha.digest(userPassword.getBytes(StandardCharsets.UTF_8)));
} catch (NoSuchAlgorithmException toCatch) {
return "*";
}
}

public static String makeDigest(

Check warning on line 157 in modules/org.jkiss.utils/src/org/jkiss/utils/SecurityUtils.java

View workflow job for this annotation

GitHub Actions / Check / Lint

[checkstyle] reported by reviewdog 🐶 All overloaded methods should be placed next to each other. Previous overloaded method located at line '128'. Raw Output: /github/workspace/./modules/org.jkiss.utils/src/org/jkiss/utils/SecurityUtils.java:157:5: warning: All overloaded methods should be placed next to each other. Previous overloaded method located at line '128'. (com.puppycrawl.tools.checkstyle.checks.coding.OverloadMethodsDeclarationOrderCheck)
String userPassword) {
try {
MessageDigest md5 =
MessageDigest.getInstance(ECRYPTION_ALGORYTHM);
MessageDigest.getInstance(HASH_ALGORYTHM_MD5);

return CommonUtils.toHexString(md5.digest(userPassword.getBytes(StandardCharsets.UTF_8)));
} catch (NoSuchAlgorithmException toCatch) {
Expand Down
Loading