Giới thiệu
Key Hash là chuỗi ký tự bảo mật bắt buộc khi cấu hình Facebook Login cho ứng dụng Android. Bài viết hướng dẫn tạo Key Hash cho cả môi trường Development (Debug) và Release.
1. Tạo Development Key Hash
macOS / Linux
Mở Terminal và chạy lệnh:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
Mật khẩu mặc định: android
Windows
Mở Command Prompt (cmd) và chạy:
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\USERNAME\.android\debug.keystore" | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" sha1 -binary | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" base64
- Thay
USERNAMEbằng tên người dùng Windows của bạn. - Thay
PATH_TO_OPENSSL_LIBRARYbằng đường dẫn cài đặt OpenSSL (ví dụ:C:\OpenSSL-Win64). - Mật khẩu keystore debug mặc định:
android.
2. Tạo Release Key Hash
Sử dụng keystore phát hành (release keystore) của bạn:
keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64
YOUR_RELEASE_KEY_ALIAS: Alias của khóa ký phát hành.YOUR_RELEASE_KEY_PATH: Đường dẫn file keystore phát hành (file .jks hoặc .keystore).- Nhập mật khẩu keystore khi được yêu cầu.
3. Cấu hình trên Facebook Developer Console
- Truy cập Facebook Developers → Chọn App của bạn.
- Vào Settings → Basic → Android.
- Dán Key Hash vừa tạo vào trường Key Hashes.
- Lưu thay đổi.

Lưu ý quan trọng
- Cần thêm cả Development và Release Key Hash để app hoạt động cả khi debug và khi phát hành trên Play Store.
- Nếu thay đổi keystore ký phát hành, phải tạo lại Release Key Hash và cập nhật lại.
- Trên Windows, nếu chưa cài OpenSSL, tải tại Win32OpenSSL.