【问题标题】:Reverse hashing in node js?节点js中的反向散列?
【发布时间】:2017-12-31 00:44:11
【问题描述】:

我正在使用下面的代码来散列数据,它工作正常。 从 crypto website

const crypto = require('crypto');

const secret = 'abcdefg';
const hash = crypto.createHmac('sha256', secret)
                   .update('I love cupcakes')
                   .digest('hex');
console.log(hash);
// Prints:
//   c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e

我的问题是如何扭转这种局面? 如何再次将数据取消散列为普通文本?

【问题讨论】:

标签: angularjs node.js encryption hash


【解决方案1】:

哈希不能被反转...你需要一个密码。这是我的小、非常简单的秘密课程。

import crypto from 'crypto'
let Secret = new (function (){
    "use strict";

    let world_enc = "utf8"
    let secret_enc = "hex";
    let key = "some_secret_key";

    this.hide = function(payload){
        let cipher = crypto.createCipher('aes128', key);
        let hash = cipher.update(payload, world_enc, secret_enc);
        hash += cipher.final(secret_enc);
        return hash;
    };
    this.reveal = function(hash){
        let sha1 = crypto.createDecipher('aes128', key);
        let payload = sha1.update(hash, secret_enc, world_enc);
        payload += sha1.final(world_enc);
        return payload;
    }
});

export {Secret};

【讨论】:

    猜你喜欢
    • 2020-04-17
    • 2020-06-03
    • 2021-07-08
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2023-02-21
    • 2012-01-14
    相关资源
    最近更新 更多