From 5bd2ec09ab1f3c588e26b98be6333a783733ee20 Mon Sep 17 00:00:00 2001 From: Luigi Asprino Date: Mon, 16 Sep 2024 09:43:23 +0200 Subject: [PATCH] #504 --- .../html/org/apache/any23/rdf/RDFUtils.java | 5 +- .../html/org/apache/any23/util/MathUtils.java | 67 ------------------- 2 files changed, 2 insertions(+), 70 deletions(-) delete mode 100644 sparql-anything-html/src/main/java/io/github/sparqlanything/html/org/apache/any23/util/MathUtils.java diff --git a/sparql-anything-html/src/main/java/io/github/sparqlanything/html/org/apache/any23/rdf/RDFUtils.java b/sparql-anything-html/src/main/java/io/github/sparqlanything/html/org/apache/any23/rdf/RDFUtils.java index 45cbe057..053cf13d 100644 --- a/sparql-anything-html/src/main/java/io/github/sparqlanything/html/org/apache/any23/rdf/RDFUtils.java +++ b/sparql-anything-html/src/main/java/io/github/sparqlanything/html/org/apache/any23/rdf/RDFUtils.java @@ -16,9 +16,8 @@ package io.github.sparqlanything.html.org.apache.any23.rdf; -import io.github.sparqlanything.html.org.apache.any23.rdf.PopularPrefixes; -import io.github.sparqlanything.html.org.apache.any23.util.MathUtils; import io.github.sparqlanything.html.org.apache.any23.util.StringUtils; +import org.apache.commons.codec.digest.DigestUtils; import org.eclipse.rdf4j.model.BNode; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Literal; @@ -382,7 +381,7 @@ public static BNode bnode() { * @return the valid {@link BNode} */ public static BNode getBNode(String id) { - return valueFactory.createBNode("node" + MathUtils.md5(id)); + return valueFactory.createBNode("node" + DigestUtils.md5Hex(id)); } /** diff --git a/sparql-anything-html/src/main/java/io/github/sparqlanything/html/org/apache/any23/util/MathUtils.java b/sparql-anything-html/src/main/java/io/github/sparqlanything/html/org/apache/any23/util/MathUtils.java deleted file mode 100644 index c97d013f..00000000 --- a/sparql-anything-html/src/main/java/io/github/sparqlanything/html/org/apache/any23/util/MathUtils.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2024 SPARQL Anything Contributors @ http://github.com/sparql-anything - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.github.sparqlanything.html.org.apache.any23.util; - -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -/** - * Mathematical utility functions. - * - * @author Michele Mostarda (mostarda@fbk.eu) - * @author Davide Palmisano (palmisano@fbk.eu) - */ -public class MathUtils { - - private MathUtils() { - } - - /** - *

- * Create a MD5 weak hash for a given string. - *

- *

- * N.B. This method MUST never be used in a sensitive context. Examples of such usage include (i) - * User-password storage, (ii) Security token generation (used to confirm e-mail when registering on a website, - * reset password, etc...), (iii) To compute some message integrity. - *

- * Current usage is limited to {@link io.github.sparqlanything.html.org.apache.any23.rdf.RDFUtils#getBNode(String)} which is fine for the creation - * of blank node(s). - * - * @param s - * input string to create an MD5 hash for. - * - * @return a string representation of a MD5 {@link MessageDigest} - */ - public static final String md5(String s) { - try { - MessageDigest md5 = MessageDigest.getInstance("MD5"); - md5.reset(); - md5.update(s.getBytes(StandardCharsets.UTF_8)); - byte[] digest = md5.digest(); - StringBuffer result = new StringBuffer(); - for (byte b : digest) { - result.append(Integer.toHexString(0xFF & b)); - } - return result.toString(); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("Should never happen, MD5 is supported", e); - } - } - -}