-1

This is a something like signinig report's my app:

Variant: release
Config: config
Store: C:\Users\Superman\Desktop\web.jks
Alias: web
MD5: 8C:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
SHA1: D3:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
SHA-256: A0:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
Valid until: Sunday, December 4, 2044

Is there a way to get this code(MD5, SHA1, SHA-256) through Android programming? I want to save one of them on the server. When using the app, these values should be checked with the values stored in the server, if it is not equal exit and kill the process (I do this to prevent my app from cracking)

Super Man
  • 49
  • 1
  • 9
  • 1
    https://stackoverflow.com/questions/304268/getting-a-files-md5-checksum-in-java – ming chen Dec 11 '20 at 07:40
  • Thanks for answering, I did not mean to convert the file to a hash code, – Super Man Dec 11 '20 at 07:49
  • @SuperMan From [Wikipedia](https://en.wikipedia.org/wiki/SHA-1): *"In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographic **hash function**"*. --- The result of applying MD5, SHA1, and SHA-256 are all hash codes. – Andreas Dec 11 '20 at 08:08
  • @Andreas I understand but my purpose that Do something similar to the Clash of clans game, In the Clash of clans game, first, the game files will be checked and if there are any changes in the files, you will be prevented to entering the game. – Super Man Dec 11 '20 at 08:21
  • @SuperMan I was commenting on your *contradiction*, that you want SHA-1 but not a hash code, given that a SHA-1 *is* a hash code, aka a digest. – Andreas Dec 11 '20 at 10:18

2 Answers2

1

It seems that you are looking for a version check. If so, you are misunderstanding the purpose of hashing. Hashing is for checking data integrity and not for verifying. It makes no security difference using hash or not, if you are just uploading the value and check it in the server.

ming chen
  • 550
  • 4
  • 13
1

This answer it taken from another answer Check out this function

// key like: SHA1, SHA256, MD5.
private fun get(key: String, info: PackageInfo) {
    try {
        for (signature in info.signatures) {
            val md: MessageDigest = MessageDigest.getInstance(key)
            md.update(signature.toByteArray())
            val digest: ByteArray = md.digest()
            val toRet = StringBuilder()
            for (i in digest.indices) {
                if (i != 0) toRet.append(":")
                val b: Byte = digest[i] and 0xff.toByte()
                val hex = Integer.toHexString(b.toInt())
                if (hex.length == 1) toRet.append("0")
                toRet.append(hex)
            }
            Log.d(TAG, "key: $key $toRet")
        }
    } catch (e1: PackageManager.NameNotFoundException) {
        Log.e(TAG, e1.toString())
    } catch (e: NoSuchAlgorithmException) {
        Log.e(TAG, e.toString())
    } catch (e: Exception) {
        Log.e(TAG, e.toString())
    }
}

To use it call it like this

get("SHA1", packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES))
Mohammad Khair
  • 436
  • 6
  • 15