繁体   English   中英

如何在区块链中解密?

[英]How to decrypt in BlockChain?

我被要求将 BlockChain 用于我正在构建的 web 应用程序,我之前没有听说过它,在搜索了一些关于它的信息之后,现在我明白了它是关于什么的。 因此,基本上它以块的形式加密了一些数据,这样,数据是安全的。

例如,我有这个从互联网上获取的代码:

const SHA256 = require('crypto-js/sha256')

class Block {
    constructor(timestamp, data) {
        this.index = 0;
        this.timestamp = timestamp;
        this.data = data;
        this.previousHash = "0";
        this.hash = this.calculateHash();
        this.nonce = 0;
    }

    calculateHash() {
        return SHA256(this.index + this.previousHash + this.timestamp + this.data + this.nonce).toString();
    }

    mineBlock(difficulty) {

    }
}

class Blockchain{
    constructor() {
        this.chain = [this.createGenesis()];
    }

    createGenesis() {
        return new Block(0, "01/01/2017", "Genesis block", "0")
    }

    latestBlock() {
        return this.chain[this.chain.length - 1]
    }

    addBlock(newBlock){
        newBlock.previousHash = this.latestBlock().hash;
        newBlock.hash = newBlock.calculateHash();
        this.chain.push(newBlock);
    }

    checkValid() {
        for(let i = 1; i < this.chain.length; i++) {
            const currentBlock = this.chain[i];
            const previousBlock = this.chain[i - 1];

            if (currentBlock.hash !== currentBlock.calculateHash()) {
                return false;
            }

            if (currentBlock.previousHash !== previousBlock.hash) {
                return false;
            }
        }

        return true;
    }
}

let jsChain = new Blockchain();
jsChain.addBlock(new Block("12/25/2017", {amount: 5}));
jsChain.addBlock(new Block("12/26/2017", {amount: 10}));

这是结果: 在此处输入图像描述

如您所见,我们已经在块中加密了“创世块”(如果我没记错的话)。

好的,如果我想解密数据以获取“创世块”怎么办? 这可能吗?

我是新手,所以我觉得有点困惑......我了解它的含义,但我不知道如何将它实施到我的 web 应用程序中。 我的 web 应用程序基本上从数据库中获取一些信息,向最终用户显示这些信息,最终用户将 email 发送给必须通过链接付款的客户。

区块链不是要加密数据以保证其“安全”; 他们是关于创建一个需要多方同意的 state 更改的可审计分类帐。 就比特币而言,它们代表了货币在不同钱包中的分布,并记录了改变这种分布的交易。

区块链是一项非常专业的技术,虽然在少数情况下它们很有用,但也有很多人在寻找适合解决方案的问题。 你最好先分析你的实际问题,然后寻找解决这些问题的技术。

在这种情况下,您的第一要务应该是一般安全性——如果有人设法在您的内部数据库上运行UPDATE ,那么已经出现了非常严重的问题。 作为“纵深防御”的一部分,您可能还需要对已进行的更改进行审计跟踪。 这可能意味着选择一种数据库技术,forms 是一种仅附加分类帐,但与传统区块链不同,您可能不需要基于分布式共识。 您可能会发现,实际上拥有一个单独安全的审核日志,您可以交叉检查是否发生任何可疑情况,这对于您所期望的场景来说已经足够了。

最后,如果您确实认为基于区块链的分类账可以解决您遇到的实际问题,请寻找可以利用的现有实现,出于同样的原因,您不会尝试从头开始编写 MySQL。

暂无
暂无

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

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