代码获取sha1
private fun getSHA1() {
val packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES)
val signatures: Array<Signature> = packageInfo.signatures
val cert = signatures[0].toByteArray()
val md = MessageDigest.getInstance("SHA1")
val sha1 = md.digest(cert)
val hexDigest: String = byte2HexFormatted(sha1)
Log.d("SHA1:", hexDigest)
}
///FF:48:35:A6:51:4D:74:EB:C7:39:21:C6:36:F7:76:C1:11:7B:A6:0E
private fun byte2HexFormatted(arr: ByteArray): String {
val str = StringBuilder(arr.size * 2)
for (i in arr.indices) {
var h = Integer.toHexString(arr[i].toInt())
val l = h.length
if (l == 1) {
h = "0$h"
}
if (l > 2) {
h = h.substring(l - 2, l)
}
str.append(h.toUpperCase())
if (i < arr.size - 1) {
str.append(':')
}
}
return str.toString()
}
///ff4835a6514d74ebc73921c636f776c1117ba60e
fun byte2hex(src: ByteArray): String {
val stringBuilder = StringBuilder("")
for (i in 0 until src.size) {
val v = src[i].toInt() and 0xFF
val hv = Integer.toHexString(v)
if (hv.length < 2) {
stringBuilder.append(0)
}
stringBuilder.append(hv)
}
return stringBuilder.toString()
}
命令获取sha1
iMES_APP.jks 是 你的签名文件
keytool -v -list -keystore iMES_APP.jks
网友评论