【代码】Android SDK平台获取高唯一性设备识别码

注意:由于获取的设备信息完全可以通过诸如hook拦截等手段伪造,因此不能简单通过代码获取到数据作为判断用户身份的唯一凭据!(某些apk竟然通过imsi,imei来为用户自动登录...)
private static String getUniqueID(Context paramContext)
  {
    for (;;)
    {
      byte[] arrayOfByte;
      int i;
      try
      {
        String str1 = ((TelephonyManager)paramContext.getSystemService("phone")).getDeviceId();
        String str2 = "35" + Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10 + Build.USER.length() % 10;
        String str3 = Settings.Secure.getString(paramContext.getContentResolver(), "android_id");
        String str4 = ((WifiManager)paramContext.getSystemService("wifi")).getConnectionInfo().getMacAddress();
        String str5 = str1 + str2 + str3 + str4;
        try
        {
          MessageDigest localMessageDigest2 = MessageDigest.getInstance("MD5");
          localMessageDigest1 = localMessageDigest2;
        }
        catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
        {
          String str7;
          localNoSuchAlgorithmException.printStackTrace();
          MessageDigest localMessageDigest1 = null;
          continue;
        }
        localMessageDigest1.update(str5.getBytes(), 0, str5.length());
        arrayOfByte = localMessageDigest1.digest();
        localObject = new String();
        i = 0;
        if (i >= arrayOfByte.length)
        {
          str7 = ((String)localObject).toUpperCase();
          Log.e("uid", str7);
          return str7;
        }
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        return "";
      }
      int j = 0xFF & arrayOfByte[i];
      if (j <= 15) {
        localObject = localObject + "0";
      }
      String str6 = localObject + Integer.toHexString(j);
      Object localObject = str6;
      i++;
    }
  }

你可能感兴趣的:(【代码】Android SDK平台获取高唯一性设备识别码)