1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Android] コードで簡単にHash Keyをもらいたい。

Last updated at Posted at 2018-05-30

以前には。

こんにちは。以前簡単にSHA(Secure Hash Algorithm)をもらう方を書いたことがあります。
Android Studioで簡単なSHA-1発給

なぜ?

image.png
あ。。。
面倒くさい

今回は。

今回はコードで簡単にハッシュ キーを取得してみましょう。

Code;

method.java
     /**
     * これなら、簡単にSHA取得でしる。
     * @author : Dreamwalker.
     */
    
    private void printKeyHash(){
        try {
            PackageInfo info = getPackageManager().getPackageInfo("your Package Naem", PackageManager.GET_SIGNATURES);

            for (android.content.pm.Signature s : info.signatures){
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(s.toByteArray());
                Log.e(TAG, "printKeyHash: " + android.util.Base64.encodeToString(md.digest(), android.util.Base64.DEFAULT));
            }

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }

なにをもらえる?

Algorithm API
MD5 1+
SHA-1 1+
SHA-224 1-8,22+
SHA-256 1+
SHA-384 1+
SHA-512 1+

結局どっち?

Firebase - Android Studioで簡単なSHA-1発給
Facebook - Android コードで簡単にHash Keyをもらいたい

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?