简体   繁体   English

如何从Ruby中5字加密哈希中找到SHA1加密字符串?

[英]How to find a SHA1 encrypted string from the 5-word encrypted hash in Ruby?

Say you're encrypting the string "alextoul" with CryptoJS.SHA1. 假设您正在使用CryptoJS.SHA1加密字符串“ alextoul”。

As explained in the source below you get an object that looks like that: 如以下源代码中所述,您将获得一个看起来像这样的对象:

CryptoJS.SHA1("alextoul") = {words: { 0: 1025575641 1: -2026381578 2: 1077518901 3: 1028391820 4: 1049226021 }} CryptoJS.SHA1(“ alextoul”)= {单词:{0:1025575641 1:-2026381578 2:1077518901 3:1028391820 4:1049226021}}

Turns out if you convert this to a string you get: 原来,如果将其转换为字符串,则会得到:

CryptoJS.SHA1("alextoul").ToString() = "3d210ad98737def64039a2353d4c038c3e89eb25" CryptoJS.SHA1(“ alextoul”)。ToString()=“ 3d210ad98737def64039a2353d4c038c3e89eb25”

Now what I'm trying to do is find the string above ("3d210ad98737def64039a2353d4c038c3e89eb25") from the 5 words but in Ruby. 现在,我想做的是从Ruby中的5个单词中找到上面的字符串(“ 3d210ad98737def64039a2353d4c038c3e89eb25”)。

thefunctionineed(params[:words]) # Equal to "3d210ad98737def64039a2353d4c038c3e89eb25" thefunctionineed(params [:words])#等于“ 3d210ad98737def64039a2353d4c038c3e89eb25”

Source: https://code.google.com/p/crypto-js/#The_Hasher_Output 来源: https//code.google.com/p/crypto-js/#The_Hasher_Output

Just reading the source: 只需阅读源代码:

https://code.google.com/p/crypto-js/source/browse/tags/3.1.2/src/core.js#181 --> https://code.google.com/p/crypto-js/source/browse/tags/3.1.2/src/core.js#181- >

https://code.google.com/p/crypto-js/source/browse/tags/3.1.2/src/core.js#306 --> https://code.google.com/p/crypto-js/source/browse/tags/3.1.2/src/core.js#306- >

function stringify(wordArray) {
        // Shortcuts
        var words = wordArray.words;
        var sigBytes = wordArray.sigBytes;

        // Convert
        var hexChars = [];
        for (var i = 0; i < sigBytes; i++) {
            var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
            hexChars.push((bite >>> 4).toString(16));
            hexChars.push((bite & 0x0f).toString(16));
        }

        return hexChars.join('');
    }

Then call 然后打电话

stringify(CryptoJS.SHA1("alextoul"))

Sorry I don't know ruby well enough to port that 对不起,我对红宝石的了解不足以移植

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM