Class HashUtils
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringhashString(String input, String algorithm) Generates a hash string for the given input using the specified algorithm.
-
Constructor Details
-
HashUtils
private HashUtils()Private constructor to prevent instantiation. ThrowsNaftahBugErrorif called.
-
-
Method Details
-
hashString
Generates a hash string for the given input using the specified algorithm.- Parameters:
input- the input string to hashalgorithm- 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
-