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


TypeScript sjcl.bitArray类代码示例

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


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

示例1: bitsToBytes

function bitsToBytes(arr) {
    var out = [], bl = sjcl.bitArray.bitLength(arr), i, tmp;
    for (i = 0; i < bl / 8; i++) {
        if ((i & 3) === 0) {
            tmp = arr[i / 4];
        }
        out.push(tmp >>> 24);
        tmp <<= 8;
    }
    return out;
}
开发者ID:Druson,项目名称:fabric,代码行数:11,代码来源:crypto.ts

示例2: hkdf2

    /** HKDF with the specified hash function.
     * @param {bitArray} ikm The input keying material.
     * @param {Number} keyBitLength The output key length, in bits.
     * @param {String|bitArray} salt The salt for HKDF.
     * @param {String|bitArray} info The info for HKDF.
     * @param {Object} [Hash=sjcl.hash.sha256] The hash function to use.
     * @return {bitArray} derived key.
     */
    private static hkdf2(ikm, keyBitLength, salt, info, Hash) {
        var hmac, key, i, hashLen, loops, curOut, ret = [];

        // Hash = Hash || sjcl.hash.sha256;
        if (typeof info === "string") {
            info = sjcl.codec.utf8String.toBits(info);
        } else if (!info) {
            info = sjcl.codec.utf8String.toBits('');
        }
        if (typeof salt === "string") {
            salt = sjcl.codec.utf8String.toBits(salt);
        } else if (!salt) {
            salt = [];
        }

        hmac = new sjcl.misc.hmac(salt, Hash);
        //key = hmac.mac(ikm);
        hmac.update(ikm);
        key = hmac.digest();
        // debug("prk: %j", new Buffer(bitsToBytes(key)).toString('hex'));
        hashLen = sjcl.bitArray.bitLength(key);

        loops = Math.ceil(keyBitLength / hashLen);
        if (loops > 255) {
            throw new sjcl.exception.invalid("key bit length is too large for hkdf");
        }

        curOut = [];
        for (i = 1; i <= loops; i++) {
            hmac = new sjcl.misc.hmac(key, Hash);
            hmac.update(curOut);
            hmac.update(info);
            // debug('sjcl.bitArray.partial(8, i): %j', sjcl.bitArray.partial(8, i));
            hmac.update(bytesToBits([i]));

            // hmac.update([sjcl.bitArray.partial(8, i)]);
            curOut = hmac.digest();
            ret = sjcl.bitArray.concat(ret, curOut);
        }
        return sjcl.bitArray.clamp(ret, keyBitLength);
    }
开发者ID:Druson,项目名称:fabric,代码行数:49,代码来源:crypto.ts

示例3: bytesToBits

/** Convert from an array of bytes to a bitArray. */
function bytesToBits(bytes) {
    var out = [], i, tmp = 0;
    for (i = 0; i < bytes.length; i++) {
        tmp = tmp << 8 | bytes[i];
        if ((i & 3) === 3) {
            out.push(tmp);
            tmp = 0;
        }
    }
    if (i & 3) {
        out.push(sjcl.bitArray.partial(8 * (i & 3), tmp));
    }
    return out;
}
开发者ID:Druson,项目名称:fabric,代码行数:15,代码来源:crypto.ts


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