You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Signature.hashCode是否指向正确哈希?sign.hashCode()返回签名还是内存对象哈希?

Android Signature.hashCode() Explained

Let's clear this up directly: when you call sign.hashCode() in your code, it returns a hash value derived from the actual signature data, not the object's memory address.

Here's the breakdown:

  • By default, Object.hashCode() returns a value tied to an object's memory identity, but Android's Signature class explicitly overrides this method (along with equals()) to calculate the hash based on the raw signature bytes it encapsulates.
  • This design makes perfect sense for a class representing app signatures: two distinct Signature instances that hold identical signature data should be treated as equal, and thus return the same hashCode—even if they're separate objects in memory.

If you want to verify this behavior yourself, you could compute a hash from the raw signature bytes (using sign.toByteArray()) and see that it aligns logically with the hashCode() result (note: hashCode() returns a 32-bit integer, while full signature hashes like SHA-256 are longer, but the core link to the signature content remains).

Your code for reference:

try {
    PackageInfo packageInfo = getPackageManager().getPackageInfo(
        "com.klxx.as", 
        PackageManager.GET_SIGNATURES
    );
    Signature[] signs = packageInfo.signatures;
    Signature sign = signs[0];
    Log.i("test", "hashCode : "+sign.hashCode());
} catch (Exception e) {
    e.printStackTrace();
}

内容的提问来源于stack exchange,提问作者Hossein Shahdoost

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:41:05