格式化

廣告

廣告2

2018年9月17日 星期一

Facebook hash key 金鑰雜湊取得方法

只需要能跑Android即可拿到hash Key 不需要讓windows再額外安裝openssl


  PackageInfo info;
  try
  {
   info = getPackageManager().getPackageInfo("com.unood.siangtienhu", PackageManager.GET_SIGNATURES);
   for (Signature signature : info.signatures)
   {
    MessageDigest md;
    md = MessageDigest.getInstance("SHA");
    md.update(signature.toByteArray());
    String KeyResult = new String(Base64.encode(md.digest(), 0));//String something = new String(Base64.encodeBytes(md.digest()));
    Log.e("hash key", KeyResult);
    Toast.makeText(this, "My FB Key is \n" + KeyResult, Toast.LENGTH_LONG).show();
   }
  }
  catch (PackageManager.NameNotFoundException e1)
  {
   Log.e("name not found", e1.toString());
  }
  catch (NoSuchAlgorithmException e)
  {
   Log.e("no such an algorithm", e.toString());
  }
  catch (Exception e) {Log.e("exception", e.toString());}

沒有留言 :