]> git.basschouten.com Git - openhab-addons.git/blob
e5caf255762c992b8c218ccf5115f87281bd3a0e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.imperihome.internal.util;
14
15 import java.math.BigInteger;
16 import java.nio.charset.StandardCharsets;
17 import java.security.MessageDigest;
18 import java.security.NoSuchAlgorithmException;
19
20 /**
21  * Digest utility.
22  *
23  * @author Pepijn de Geus - Initial contribution
24  */
25 public final class DigestUtil {
26
27     public static String sha1(String input) {
28         try {
29             MessageDigest crypt = MessageDigest.getInstance("SHA-1");
30             crypt.reset();
31             crypt.update(input.getBytes(StandardCharsets.UTF_8));
32
33             return new BigInteger(1, crypt.digest()).toString(16);
34         } catch (NoSuchAlgorithmException e) {
35             throw new RuntimeException("Could not generate SHA-1 hash", e);
36         }
37     }
38
39     // Hidden constructor
40     private DigestUtil() {
41     }
42 }