You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/eu/righettod/SecurityUtils.java
+32Lines changed: 32 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,9 @@
32
32
importjava.net.InetAddress;
33
33
importjava.net.MalformedURLException;
34
34
importjava.net.URL;
35
+
importjava.nio.charset.StandardCharsets;
35
36
importjava.nio.file.Files;
37
+
importjava.security.MessageDigest;
36
38
importjava.util.*;
37
39
importjava.util.regex.Pattern;
38
40
importjava.util.zip.ZipEntry;
@@ -532,4 +534,34 @@ public static boolean isPublicIPAddress(String ip) {
532
534
}
533
535
returnisValid;
534
536
}
537
+
538
+
/**
539
+
* Compute a SHA256 hash from an input composed of a collection of strings.<br>
540
+
* This method take care to build the source string in a way to prevent this source string to be prone to abuse<br>
541
+
* targeting the different parts composing it.<br>
542
+
* Example of abuse:<br>
543
+
* <code>SHA256("Hello" + "My" + "World!!!")</code> is not equals to <code>SHA256("Hell" + "oMyW" + "orld!!!")</code>
544
+
*
545
+
* @param parts Ordered list of strings to use to build the input string for which the hash must be computed on. No null value is accepted on object composing the collection.
546
+
* @return The hash, as an array of bytes, to allow caller to convert it to the final representation wanted (HEX, Base64, etc.). If the collection passed is null or empty then the method return null.
0 commit comments