当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript js-sha256.sha256函数代码示例

本文整理汇总了TypeScript中js-sha256.sha256函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sha256函数的具体用法?TypeScript sha256怎么用?TypeScript sha256使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sha256函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getMac256Hash


//.........这里部分代码省略.........
            }

            for (i = 0; i < sA.length; i++) {
                sC += (sA.charAt(i) === sB.charAt(i)) ? '0' : '1';
            }

            return parseInt(sC.toString(), 2);
        }

        function cS64_C(pdwData:Array<string>, pInHash:Array<number>, pOutHash:Array<Number>):boolean {
            var MODULUS = 2147483647;
            if ((pdwData.length < 2) || ((pdwData.length & 1) === 1)) {
                return false;
            }

            var ulCS64_a = pInHash[0] & MODULUS;
            var ulCS64_b = pInHash[1] & MODULUS;
            var ulCS64_c = pInHash[2] & MODULUS;
            var ulCS64_d = pInHash[3] & MODULUS;
            var ulCS64_e = 242854337;

            var CS64_a = bigInt(ulCS64_a.toString());//decRadix === 1000????
            var CS64_b = bigInt(ulCS64_b.toString());
            var CS64_c = bigInt(ulCS64_c.toString());
            var CS64_d = bigInt(ulCS64_d.toString());
            var CS64_e = bigInt(ulCS64_e.toString());

            var pos = 0;
            var mod = bigInt(MODULUS.toString());
            var qwDatum = bigInt('0');
            var qwMAC = bigInt('0');
            var qwSum = bigInt('0');

            for (var i = 0; i < pdwData.length / 2; i++) {
                qwDatum = bigInt(pdwData[pos++].toString());
                qwDatum.multiply(CS64_e);
                qwDatum.mod(mod);
                qwMAC.add(qwDatum);
                qwMAC.multiply(CS64_a);
                qwMAC.add(CS64_b);
                qwMAC.mod(mod);
                qwSum.add(qwMAC);
                qwMAC.add(bigInt(pdwData[pos++].toString()));
                qwMAC.multiply(CS64_c);
                qwMAC.add(CS64_d);
                qwMAC.mod(mod);
                qwSum.add(qwMAC);
            }

            qwMAC.add(CS64_b);
            qwMAC.mod(mod);
            qwSum.add(CS64_d);
            qwSum.mod(mod);
            pOutHash[0] = parseInt(qwMAC.toString(10), 10);
            pOutHash[1] = parseInt(qwSum.toString(10), 10);

            return true;
        }

        var clearText = challenge + appId;
        var remaining = 8 - (clearText.length % 8);
        if (remaining !== 8) {
            clearText = padRight(clearText, clearText.length + remaining, '0');
        }

        var cchClearText = clearText.length / 4;
        var pClearText: any[] = [];
        var i: any;
        var pos: any;
        for (i = 0, pos = 0; i < cchClearText; i++) {
            pClearText.splice(i, 0, 0);
            pClearText[i] = pClearText[i] + clearText.charCodeAt(pos++) * 1;
            pClearText[i] = pClearText[i] + clearText.charCodeAt(pos++) * 256;
            pClearText[i] = pClearText[i] + clearText.charCodeAt(pos++) * 65536;
            pClearText[i] = pClearText[i] + clearText.charCodeAt(pos++) * 16777216;
        }

        var sha256Hash = new Array(4);
        var hash:string = sha256.sha256(challenge + key).toUpperCase();
        for (i = 0, pos = 0; i < sha256Hash.length; i++) {
            sha256Hash[i] = 0;
            sha256Hash[i] += parseHexInt(hash.substr(pos, 2)) * 1;
            pos += 2;
            sha256Hash[i] += parseHexInt(hash.substr(pos, 2)) * 256;
            pos += 2;
            sha256Hash[i] += parseHexInt(hash.substr(pos, 2)) * 65536;
            pos += 2;
            sha256Hash[i] += parseHexInt(hash.substr(pos, 2)) * 16777216;
            pos += 2;
        }

        var macHash = new Array(2);
        cS64_C(pClearText, sha256Hash, macHash);
        var a = int64Xor(sha256Hash[0], macHash[0]);
        var b = int64Xor(sha256Hash[1], macHash[1]);
        var c = int64Xor(sha256Hash[2], macHash[0]);
        var d = int64Xor(sha256Hash[3], macHash[1]);

        return int32ToHexString(a) + int32ToHexString(b) + int32ToHexString(c) + int32ToHexString(d);
    }
开发者ID:SwadicalRag,项目名称:skyweb,代码行数:101,代码来源:utils.ts

示例2: test

test('sha256(ArrayBuffer)', (t) => {
  t.plan(1);
  t.equal(sha256(new ArrayBuffer(0)), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
});
开发者ID:demurgos,项目名称:typed-js-sha256,代码行数:4,代码来源:test.ts


注:本文中的js-sha256.sha256函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。