التجزئة/التشفير
HMAC Generator
حساب HMAC (رمز مصادقة الرسائل المعتمد على الهاش) لنص أو ملف باستخدام مفتاح سري — بثماني خوارزميات دفعة واحدة: MD5, SHA-1, SHA-256, SHA-384, SHA-512, SHA3-256, SHA3-512, RIPEMD-160.
HMAC (Hash-based Message Authentication Code) is a hash computed together with a secret key, proving a message hasn't changed and was sent by someone who knows that key. Unlike a plain hash, an HMAC can't be forged without knowing the secret.
How to use it
- Enter text or a file and a secret key — the HMAC is computed instantly with eight algorithms at once (MD5, SHA-1, SHA-2, SHA3, RIPEMD-160).
- Copy the variant you need to verify a signature or compare against an expected value.
- The same input and key always produce the same HMAC — handy for checking against a signature received from another system.
Common uses
- Verifying a webhook signature from a payment service or API (most sign the payload with HMAC-SHA256).
- Generating a request signature for an API that requires HMAC authentication.
- Debugging a mismatched signature — checking the key, input encoding, and algorithm one at a time.
Things to keep in mind
HMAC protects against tampering and confirms the sender's authenticity, but it doesn't encrypt the message itself — the content stays readable.
A mismatched HMAC is most often caused by different data encoding (e.g. JSON field order) or a stray whitespace or line break, not by a bug in the algorithm itself.
مقالة عن هذه الأداة: HMAC: كيف تختلف التجزئة بمفتاح عن التجزئة العادية
الأسئلة الشائعة
ما الفرق بين HMAC والتجزئة العادية (hash)؟
التجزئة العادية تنتج بصمة للبيانات دون مفتاح، بينما HMAC يستخدم مفتاحًا سريًا مشتركًا فيوفر مصادقة تثبت أن الرسالة أُنشئت من طرف يملك المفتاح، وليس مجرد بصمة عامة.
هل يمكن حساب HMAC بدون إدخال مفتاح سري؟
لا، المفتاح السري إلزامي لخوارزمية HMAC؛ بدونه لا معنى للعملية لأن أمانها يعتمد بالكامل على سرية هذا المفتاح.
كيف أختار الخوارزمية وطول المفتاح المناسبين؟
يُفضَّل استخدام HMAC-SHA-256 أو أعلى للاستخدامات الحديثة، مع مفتاح عشوائي بطول لا يقل عن طول ناتج التجزئة نفسها لتحقيق أقصى مقاومة ممكنة.
لماذا لا يجوز مقارنة HMAC بعامل المساواة العادي؟
مقارنة السلاسل العادية تتوقف عند أول اختلاف، ويكشف زمن التنفيذ للمهاجم عدد الأحرف الأولى التي خمّنها بشكل صحيح (هجوم توقيت). المطلوب دوال مقارنة بزمن ثابت، مثل hash_equals في PHP.
هل يمكن استخدام نفس المفتاح لعدة أغراض مختلفة؟
لا يُنصح بذلك. إذا استُخدم المفتاح السري نفسه لتوقيع الويب هوك ولغرض آخر، فإن اختراق نظام واحد يعرّض النظام الآخر تلقائيًا للخطر — يُفضَّل توليد مفتاح منفصل لكل غرض.