不羁的小狗 2022-03-31 11:48 采纳率: 33.3%
浏览 242
已结题

一段js代码转java代码,求小伙伴出现


module.exports = get_id;

function get_id(userAgent) {
    function generate_sign() {
        var webdriver = 'false'
        var language = 'zh-CN'
        var colorDepth = '24'
        var deviceMemory = '8'
        var pixelRatio = '4'  // 1 or 4
        var timezoneOffset = '-480'
        var timezone = 'Asia/Shanghai'
        var platform = 'Win32'
        var plugins = 'PDF Viewer::Portable Document Format::application/pdf~pdf,text/pdf~pdf,Chrome PDF Viewer::Portable Document Format::application/pdf~pdf,text/pdf~pdf,Chromium PDF Viewer::Portable Document Format::application/pdf~pdf,text/pdf~pdf,Microsoft Edge PDF Viewer::Portable Document Format::application/pdf~pdf,text/pdf~pdf,WebKit built-in PDF::Portable Document Format::application/pdf~pdf,text/pdf~pdf'
        var canvas = 'canvas winding:yes~canvas fp:10cfbbb02b2606dbc2ccb15a3cd2b558'
        var random_number = Math.random() * 124
        var salt = 'hasaki'
        return userAgent + '~~~' + webdriver + '~~~' + language + '~~~' + colorDepth + '~~~' + deviceMemory + '~~~' + pixelRatio + '~~~' + timezoneOffset + '~~~' + timezone + '~~~1~~~1~~~1~~~1~~~unknown~~~' + platform + '~~~' + plugins + '~~~' + canvas + '~~~false~~~false~~~false~~~false~~~false~~~0;false;false~~~4;7;8~~~' + random_number + salt;
    }

    function generate_id(sign) {
        for (y = function (t) {
            for (var e, n = t.length, r = n + 8, o = 16 * ((r - r % 64) / 64 + 1), i = Array(o - 1), a = 0, c = 0; c < n;)
                a = c % 4 * 8,
                    i[e = (c - c % 4) / 4] = i[e] | t.charCodeAt(c) << a,
                    c++;
            return a = c % 4 * 8,
                i[e = (c - c % 4) / 4] = i[e] | 128 << a,
                i[o - 2] = n << 3,
                i[o - 1] = n >>> 29,
                i
        }(function (t) {
            t = t.replace(/\r\n/g, "\n");
            for (var e = "", n = 0; n < t.length; n++) {
                var r = t.charCodeAt(n);
                r < 128 ? e += String.fromCharCode(r) : (127 < r && r < 2048 ? e += String.fromCharCode(r >> 6 | 192) : (e += String.fromCharCode(r >> 12 | 224),
                    e += String.fromCharCode(r >> 6 & 63 | 128)),
                    e += String.fromCharCode(63 & r | 128))
            }
            return e
        }(sign)),
                 d = 1732584193,
                 v = 4023233417,
                 h = 2562383102,
                 g = 271733878,
                 a = 0;
             a < y.length;
             a += 16)
            d = o(d = r(d = r(d = r(d = r(d = n(d = n(d = n(d = n(d = e(d = e(d = e(d = e(s = d, f = v, l = h, p = g, y[a + 0], 7, 3614090360), v = e(v, h = e(h, g = e(g, d, v, h, y[a + 1], 12, 3905402710), d, v, y[a + 2], 17, 606105819), g, d, y[a + 3], 22, 3250441966), h, g, y[a + 4], 7, 4118548399), v = e(v, h = e(h, g = e(g, d, v, h, y[a + 5], 12, 1200080426), d, v, y[a + 6], 17, 2821735955), g, d, y[a + 7], 22, 4249261313), h, g, y[a + 8], 7, 1770035416), v = e(v, h = e(h, g = e(g, d, v, h, y[a + 9], 12, 2336552879), d, v, y[a + 10], 17, 4294925233), g, d, y[a + 11], 22, 2304563134), h, g, y[a + 12], 7, 1804603682), v = e(v, h = e(h, g = e(g, d, v, h, y[a + 13], 12, 4254626195), d, v, y[a + 14], 17, 2792965006), g, d, y[a + 15], 22, 1236535329), h, g, y[a + 1], 5, 4129170786), v = n(v, h = n(h, g = n(g, d, v, h, y[a + 6], 9, 3225465664), d, v, y[a + 11], 14, 643717713), g, d, y[a + 0], 20, 3921069994), h, g, y[a + 5], 5, 3593408605), v = n(v, h = n(h, g = n(g, d, v, h, y[a + 10], 9, 38016083), d, v, y[a + 15], 14, 3634488961), g, d, y[a + 4], 20, 3889429448), h, g, y[a + 9], 5, 568446438), v = n(v, h = n(h, g = n(g, d, v, h, y[a + 14], 9, 3275163606), d, v, y[a + 3], 14, 4107603335), g, d, y[a + 8], 20, 1163531501), h, g, y[a + 13], 5, 2850285829), v = n(v, h = n(h, g = n(g, d, v, h, y[a + 2], 9, 4243563512), d, v, y[a + 7], 14, 1735328473), g, d, y[a + 12], 20, 2368359562), h, g, y[a + 5], 4, 4294588738), v = r(v, h = r(h, g = r(g, d, v, h, y[a + 8], 11, 2272392833), d, v, y[a + 11], 16, 1839030562), g, d, y[a + 14], 23, 4259657740), h, g, y[a + 1], 4, 2763975236), v = r(v, h = r(h, g = r(g, d, v, h, y[a + 4], 11, 1272893353), d, v, y[a + 7], 16, 4139469664), g, d, y[a + 10], 23, 3200236656), h, g, y[a + 13], 4, 681279174), v = r(v, h = r(h, g = r(g, d, v, h, y[a + 0], 11, 3936430074), d, v, y[a + 3], 16, 3572445317), g, d, y[a + 6], 23, 76029189), h, g, y[a + 9], 4, 3654602809), v = r(v, h = r(h, g = r(g, d, v, h, y[a + 12], 11, 3873151461), d, v, y[a + 15], 16, 530742520), g, d, y[a + 2], 23, 3299628645), h, g, y[a + 0], 6, 4096336452),
                v = o(v = o(v = o(v = o(v, h = o(h, g = o(g, d, v, h, y[a + 7], 10, 1126891415), d, v, y[a + 14], 15, 2878612391), g, d, y[a + 5], 21, 4237533241), h = o(h, g = o(g, d = o(d, v, h, g, y[a + 12], 6, 1700485571), v, h, y[a + 3], 10, 2399980690), d, v, y[a + 10], 15, 4293915773), g, d, y[a + 1], 21, 2240044497), h = o(h, g = o(g, d = o(d, v, h, g, y[a + 8], 6, 1873313359), v, h, y[a + 15], 10, 4264355552), d, v, y[a + 6], 15, 2734768916), g, d, y[a + 13], 21, 1309151649), h = o(h, g = o(g, d = o(d, v, h, g, y[a + 4], 6, 4149444226), v, h, y[a + 11], 10, 3174756917), d, v, y[a + 2], 15, 718787259), g, d, y[a + 9], 21, 3951481745),
                d = u(d, s),
                v = u(v, f),
                h = u(h, l),
                g = u(g, p);
        return (i(d) + i(v) + i(h) + i(g)).toLowerCase()
    }

    function u(t, e) {
        var n, r, o, i, a;
        return o = 2147483648 & t,
            i = 2147483648 & e,
            a = (1073741823 & t) + (1073741823 & e), (n = 1073741824 & t) & (r = 1073741824 & e) ? 2147483648 ^ a ^ o ^ i : n | r ? 1073741824 & a ? 3221225472 ^ a ^ o ^ i : 1073741824 ^ a ^ o ^ i : a ^ o ^ i
    }

    function i(t) {
        var e, n = "",
            r = "";
        for (e = 0; e <= 3; e++)
            n += (r = "0" + (t >>> 8 * e & 255).toString(16)).substr(r.length - 2, 2);
        return n
    }

    function o(t, e, n, r, o, i, a) {
        return u(c(t = u(t, u(u(n ^ (e | ~r), o), a)), i), e)
    }

    function e(t, e, n, r, o, i, a) {
        return u(c(t = u(t, u(u(e & n | ~e & r, o), a)), i), e)
    }

    function n(t, e, n, r, o, i, a) {
        return u(c(t = u(t, u(u(e & r | n & ~r, o), a)), i), e)
    }

    function r(t, e, n, r, o, i, a) {
        return u(c(t = u(t, u(u(e ^ n ^ r, o), a)), i), e)
    }

    function c(t, e) {
        return t << e | t >>> 32 - e
    }

    var sign = generate_sign()
    return generate_id(sign)
}

```javascript


```

  • 写回答

11条回答 默认 最新

  • Selenium399 2022-03-31 17:58
    关注
    
    import java.security.MessageDigest;
    import java.math.BigInteger;
    
    class Test{
        public static String generateHash(String input){
            try {
                if (null == input) {
                    return null;
                }
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(input.getBytes());
                byte[] digest = md.digest();
                BigInteger bi = new BigInteger(1, digest);
                String hashText = bi.toString(16);
                while(hashText.length() < 32){
                    hashText = "0" + hashText;
                }
                return hashText;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
        public static String get_id(String userAgent){
                String webdriver = "false";
                String language = "zh-CN";
                String colorDepth = "24";
                String deviceMemory = "8";
                String pixelRatio = "4";  // 1 or 4
                String timezoneOffset = "-480";
                String timezone = "Asia/Shanghai";
                String platform = "Win32";
                String plugins = "PDF Viewer::Portable Document Format::application/pdf~pdf,text/pdf~pdf,Chrome PDF Viewer::Portable Document Format::application/pdf~pdf,text/pdf~pdf,Chromium PDF Viewer::Portable Document Format::application/pdf~pdf,text/pdf~pdf,Microsoft Edge PDF Viewer::Portable Document Format::application/pdf~pdf,text/pdf~pdf,WebKit built-in PDF::Portable Document Format::application/pdf~pdf,text/pdf~pdf";
                String canvas = "canvas winding:yes~canvas fp:10cfbbb02b2606dbc2ccb15a3cd2b558";
                String random_number = ""+Math.random() * 124;
                String salt = "hasaki";
                String sign = userAgent + "~~~" + webdriver + "~~~" + language + "~~~" + colorDepth + "~~~" + deviceMemory + "~~~" + pixelRatio + "~~~" + timezoneOffset + "~~~" + timezone + "~~~1~~~1~~~1~~~1~~~unknown~~~" + platform + "~~~" + plugins + "~~~" + canvas + "~~~false~~~false~~~false~~~false~~~false~~~0;false;false~~~4;7;8~~~" + random_number + salt;
                return generateHash(sign);
        }
    
        public static void main(String args[]){
           System.out.println(get_id("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36"));
        }
    }
    

    其实那一长串js的加密代码就是md5的实现而已,等同于crypto.createHash('MD5').update(sign).degest('hex')

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(10条)

报告相同问题?

问题事件

  • 系统已结题 4月8日
  • 已采纳回答 3月31日
  • 创建了问题 3月31日

悬赏问题

  • ¥15 怎么制作一个人脸识别门禁系统
  • ¥20 大华dss监控平台网络关闭登不进去
  • ¥15 请使用蚁群算法解决下列问题,并给出我完整的代码
  • ¥20 关于php录入完成后,批量更新数据库
  • ¥15 请教往复密封润滑问题
  • ¥15 cocos creator发布ios包
  • ¥15 comsol压电材料数据
  • ¥35 用python实现除法算法中goldschmidt算法
  • ¥15 汇编代码转换成C代码
  • ¥15 除法算法中的归一化具体是怎么变的?