-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9eae933
commit fe20949
Showing
6 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
extensions/src/main/java/com/applogist/extensions/ApplicationUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.applogist.extensions | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import android.util.Log | ||
import java.security.MessageDigest | ||
|
||
/* | ||
* Created by Mustafa Ürgüplüoğlu on 10.04.2020. | ||
* Copyright © 2020 Mustafa Ürgüplüoğlu. All rights reserved. | ||
*/ | ||
|
||
fun Context.getApplicationSignature(packageName: String, type : String = "SHA256"): List<String> { | ||
val signatureList: List<String> | ||
try { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
// New signature | ||
val sig = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES).signingInfo | ||
signatureList = if (sig.hasMultipleSigners()) { | ||
// Send all with apkContentsSigners | ||
sig.apkContentsSigners.map { | ||
val digest = MessageDigest.getInstance(type) | ||
digest.update(it.toByteArray()) | ||
digest.digest().bytesToHex() | ||
} | ||
} else { | ||
// Send one with signingCertificateHistory | ||
sig.signingCertificateHistory.map { | ||
val digest = MessageDigest.getInstance(type) | ||
digest.update(it.toByteArray()) | ||
digest.digest().bytesToHex() | ||
} | ||
} | ||
} else { | ||
val sig = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures | ||
signatureList = sig.map { | ||
val digest = MessageDigest.getInstance(type) | ||
digest.update(it.toByteArray()) | ||
digest.digest().bytesToHex() | ||
} | ||
} | ||
|
||
return signatureList | ||
} catch (e: Exception) { | ||
Log.e("ApplicationUtils", e.toString()) | ||
} | ||
return emptyList() | ||
} |
18 changes: 18 additions & 0 deletions
18
extensions/src/main/java/com/applogist/extensions/HexUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.applogist.extensions | ||
|
||
/* | ||
* Created by Mustafa Ürgüplüoğlu on 10.04.2020. | ||
* Copyright © 2020 Mustafa Ürgüplüoğlu. All rights reserved. | ||
*/ | ||
|
||
fun ByteArray.bytesToHex(): String { | ||
val hexArray = charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F') | ||
val hexChars = CharArray(this.size * 2) | ||
var v: Int | ||
for (j in this.indices) { | ||
v = this[j].toInt() and 0xFF | ||
hexChars[j * 2] = hexArray[v.ushr(4)] | ||
hexChars[j * 2 + 1] = hexArray[v and 0x0F] | ||
} | ||
return String(hexChars) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters