How can I calculate the SHA-256 hash of a string in Android?

前端 未结 4 1500
独厮守ぢ
独厮守ぢ 2020-12-12 22:05

I\'m trying to get the SHA256 of a string in Android.

Here is the PHP code that I want to match:

echo bin2hex(mhash(MHASH_SHA256,\"asdf\"));
//output         


        
4条回答
  •  醉梦人生
    2020-12-12 22:30

    i know this has been answered but i found a Hashing Library at android arsenal and its very easy,simple and just one line of code. can hash MD5, SHA-1, SHA-256, SHA-384, or SHA-512.

    1. first add this to your gradle and sync

      implementation 'com.github.1AboveAll:Hasher:1.2'

    2. start hasing

      Hasher.Companion.hash("Hello",HashType.SHA_1);

提交回复
热议问题