Facebook gets key hashes

Source: Internet
Author: User
Tags base64 openssl openssl sha1
The key hashes is to let Facebook know that your app is not the app that was set up, so you can access the Facebook API.
Here's how to get the key hashes:

1. Download OpenSSL first


2. Place the Openssl.exe under the C:\Program files\java\jre7\bin file


3. Open cmd.exe, go to C:\Program files\java\jre7\bin, make KeyStore file, as follows
Keytool-genkey-v-keystore xxx.keystore-alias yyy-keyalg rsa-keysize 2048-validity 10000

This will give you a screenshot of KeyStore (Eclipse can also make keystore files) as follows:


Here the Xxx.keystore and yyy are defined by their own name, the following to get the hashkey of the time to use
Parameter description:
-keystore: Name
-alias: Name
-KEYALG: Algorithm

-validity: Days of validity


4. After getting KeyStore, you can get key hashes, as follows

Keytool-exportcert-alias Yyy-keystore Xxx.keystore | OpenSSL sha1-binary | OpenSSL base64

The name of the-alias and-keystore here is the name just taken, and then enter the KeyStore password to get key hashes, here is the operation screenshot:

5. Can also be obtained by code: try {
       packageinfo info = Getpackagemanager (). Getpackageinfo (  Getpackagename (),   packagemanager.get_signatures);
       for (Signature signature:info.signatures) {
          &NBSP ; MessageDigest MD = messagedigest.getinstance ("SHA");
           md.update (Signature.tobytearray ());
           string Keyhash = base64.encodetostring (Md.digest (), base64.default);
           LOG.D ("Keyhash:", "Keyhash:" +keyhash);//two times get different   here take first value
           toast.maketext (this, "FaceBook HashKey:" +keyhash, Toast.length_short). Show ();
       }
   } catch (Namenotfoundexception e) {
   } catch (NoSuchAlgorithmException e) {
  & nbsp;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.