當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。