2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ecovacs.internal.api.util;
15 import java.security.MessageDigest;
16 import java.security.NoSuchAlgorithmException;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * @author Johannes Ptaszyk - Initial contribution
26 public class MD5Util {
27 private static final Logger LOGGER = LoggerFactory.getLogger(MD5Util.class);
30 // Prevent instantiation of util class
33 public static String getMD5Hash(String input) {
36 md = MessageDigest.getInstance("MD5");
37 } catch (NoSuchAlgorithmException e) {
38 LOGGER.error("Could not get MD5 MessageDigest instance", e);
41 md.update(input.getBytes());
42 byte[] hash = md.digest();
43 StringBuilder hexString = new StringBuilder();
45 if ((0xff & b) < 0x10) {
46 hexString.append("0").append(Integer.toHexString((0xFF & b)));
48 hexString.append(Integer.toHexString(0xFF & b));
51 return hexString.toString();