Class HashUtils

java.lang.Object
org.daiitech.naftah.utils.HashUtils

public final class HashUtils extends Object
Utility class for hashing strings using various cryptographic algorithms.

This class provides static methods to generate hash digests of input strings using standard algorithms like MD5, SHA-1, SHA-256, etc.

Instantiation of this class is prevented by a private constructor that throws an exception if called.

Usage example:


 String hash = HashUtils.hashString("example", "SHA-256");
 

Note: If the provided algorithm is not supported by the current runtime environment, a NaftahBugError is thrown.

--------------------------------------------------

فئة أدوات لتجزئة النصوص باستخدام خوارزميات التشفير المختلفة.

توفر هذه الفئة طرقًا ثابتة لتوليد ملخصات التجزئة لسلاسل الإدخال باستخدام خوارزميات قياسية مثل MD5، SHA-1، SHA-256، وغيرها.

يتم منع إنشاء مثيل لهذه الفئة عبر مُنشئ خاص يرمي استثناءً إذا تم استدعاؤه.

مثال على الاستخدام:


 String hash = HashUtils.hashString("example", "SHA-256");
 

ملاحظة: إذا لم تكن الخوارزمية المقدمة مدعومة في بيئة التشغيل الحالية، سيتم رمي NaftahBugError.

Author:
Chakib Daii
  • Constructor Details

    • HashUtils

      private HashUtils()
      Private constructor to prevent instantiation. Throws NaftahBugError if called.
  • Method Details

    • hashString

      public static String hashString(String input, String algorithm)
      Generates a hash string for the given input using the specified algorithm.
      Parameters:
      input - the input string to hash
      algorithm - the name of the hashing algorithm (e.g., "MD5", "SHA-256")
      Returns:
      the resulting hash as a hexadecimal string
      Throws:
      NaftahBugError - if the specified algorithm is not supported or unavailable