久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 JS 中獲取 CryptoJS.HmacSHA256 的摘要表示

How to get digest representation of CryptoJS.HmacSHA256 in JS(如何在 JS 中獲取 CryptoJS.HmacSHA256 的摘要表示)
本文介紹了如何在 JS 中獲取 CryptoJS.HmacSHA256 的摘要表示的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我必須在摘要中生成 CryptoJS.HmacSHA256 的字符串表示(字節(jié)表示).

I have to generate string representation of CryptoJS.HmacSHA256 in digest (bytes representation).

我需要它,因?yàn)槲冶仨殢?fù)制在 javascript 中生成此類摘要的 python 代碼:

I need it because i have to duplicate python code which generate such digest in javascript:

print hmac.new("secret", "test", hashlib.sha256).digest()

')?kb??>?y+??????:?oΚ??H?   '

目標(biāo)是在 javascript 中復(fù)制上述代碼的行為.

The goal is to duplicate behaviour of code above in javascript.

你能建議我怎么做嗎?

推薦答案

如果您需要原始字節(jié),那么 CryptoJS 似乎沒有為它提供代碼.提到這是因?yàn)?code>Uint8Array和朋友缺乏跨瀏覽器兼容性.

If you need raw bytes then CryptoJS does not seem to supply code for it. It is mentioned that this is because of lack of cross browser compatibility for Uint8Array and friends.

但是,經(jīng)過搜索,我確實(shí)找到了一些由 Vincenzo Ciancia 創(chuàng)建的轉(zhuǎn)換代碼:

However, after searching, I did find some conversion code created by Vincenzo Ciancia:

CryptoJS.enc.u8array = {
    /**
     * Converts a word array to a Uint8Array.
     *
     * @param {WordArray} wordArray The word array.
     *
     * @return {Uint8Array} The Uint8Array.
     *
     * @static
     *
     * @example
     *
     *     var u8arr = CryptoJS.enc.u8array.stringify(wordArray);
     */
    stringify: function (wordArray) {
        // Shortcuts
        var words = wordArray.words;
        var sigBytes = wordArray.sigBytes;

        // Convert
        var u8 = new Uint8Array(sigBytes);
        for (var i = 0; i < sigBytes; i++) {
            var byte = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
            u8[i]=byte;
        }

        return u8;
    },

    /**
     * Converts a Uint8Array to a word array.
     *
     * @param {string} u8Str The Uint8Array.
     *
     * @return {WordArray} The word array.
     *
     * @static
     *
     * @example
     *
     *     var wordArray = CryptoJS.enc.u8array.parse(u8arr);
     */
    parse: function (u8arr) {
        // Shortcut
        var len = u8arr.length;

        // Convert
        var words = [];
        for (var i = 0; i < len; i++) {
            words[i >>> 2] |= (u8arr[i] & 0xff) << (24 - (i % 4) * 8);
        }

        return CryptoJS.lib.WordArray.create(words, len);
    }
};

當(dāng)然請注意,字節(jié)不會直接轉(zhuǎn)換為字符;你不能使用文本比較來比較 ') kb > y+ : oΚ H ' 由 python 生成.為此,您確實(shí)需要一個(gè)編碼器,例如十六進(jìn)制或 base 64.在這種情況下,請查看 來自Artjom 代替.

Note of course that bytes don't translate directly to characters; you cannot use a text compare to compare against ')?kb??>?y+??????:?oΚ??H? ' generated by python. For that you do need an encoder such as hexadecimals or base 64. In that case please look at the answer from Artjom instead.

這篇關(guān)于如何在 JS 中獲取 CryptoJS.HmacSHA256 的摘要表示的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Using discord.js to detect image and respond(使用 discord.js 檢測圖像并響應(yīng))
Check if user ID exists in Discord server(檢查 Discord 服務(wù)器中是否存在用戶 ID)
Guild Member Add does not work (discordjs)(公會成員添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 創(chuàng)建我的第一個(gè)機(jī)器人,但總是錯(cuò)誤 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何為我的 Discord.js 機(jī)器人編寫事件/命令處理程序?)
How to find a User ID from a Username in Discord.js?(如何從 Discord.js 中的用戶名中查找用戶 ID?)
主站蜘蛛池模板: 亚洲欧洲在线观看视频 | 美日韩免费 | 国产精品美女一区二区三区 | 国产区视频在线观看 | 亚洲av一级毛片 | 少妇一级淫片aaaaaaaaa | 麻豆一区一区三区四区 | 玖玖久久 | 二区不卡| 久久噜| 国产视频h | 波多野结衣中文字幕一区二区三区 | 国产精品美女久久久久久久网站 | 久久久久久天堂 | 午夜精品一区二区三区三上悠亚 | 国内精品视频免费观看 | 观看av | 成人激情视频在线观看 | 日本a视频 | 天天操天天操 | 91精品国产91久久久久福利 | 成年网站在线观看 | 亚洲成人精品在线 | 最新中文字幕在线 | 黄色大片免费观看 | 国产91在线播放精品91 | 天天看天天摸天天操 | 精品国产一区久久 | 国产精品18hdxxxⅹ在线 | 日韩在线三级 | 午夜精品久久久久久久久久久久久 | 青青草社区 | 久久综合久色欧美综合狠狠 | h视频在线播放 | 99在线免费观看 | 天天操精品视频 | 国产一区二区三区四区 | 日韩美女在线看免费观看 | 日韩一区二区在线看 | 日韩精品一区二区三区视频播放 | 99久久婷婷国产综合精品电影 |