就像我可以通过将钱包中的单个私钥解密(而不是使用GPG)将完全加密的文件存储在IPFS和区块链中一样。我只是想知道这是否可能。
您可以,但是总的来说,我建议不要这样做,因为密钥通常只能使用一次。大多数钱包不会重复使用密钥,而是为每次交易生成新密钥,以保护隐私。
但是,对于比特币,您可以使用类似这样的加密货币(对此实现的安全性进行自己的研究)。
index.js
var crypto = require("crypto");
var eccrypto = require("eccrypto");
var privateKey = new Buffer("c337ded6f56c07205fb7b391654d7d463c9e0c726869523ae6024c9bec878878", "hex");
//var publicKey = eccrypto.getPublic(privateKey);
var publicKey = new Buffer("04730a151f545f5dcdb1c6d99fb1251f5c70f216f39ba2681bcf10db16bd582e6720bc881d51f25ffbe961df6a0af24a9d39a4db3d86a7f6b3f9bf4eaac0e4006b", "hex");
// Encrypting the message for B.
eccrypto.encrypt(publicKey, Buffer("msg")).then(function(encrypted) {
console.log('Encrypted message ' + JSON.stringify(encrypted));
// B decrypting the message.
eccrypto.decrypt(privateKey, encrypted).then(function(plaintext) {
console.log("Decrypted message: ", plaintext.toString());
});
});
输出量
$ node index.js
Encrypted message {"iv":{"type":"Buffer","data":[204,13,168,25,80,255,9,233,111,60,165,204,180,126,53,65]},"ephemPublicKey":{"type":"Buffer","data":[4,192,3,65,241,134,65,186,52,52,250,61,208,189,216,167,122,206,156,152,27,173,69,152,37,138,164,5,54,189,227,88,37,243,220,183,22,204,235,37,212,110,207,66,225,244,25,92,69,223,247,175,218,228,134,210,247,190,211,248,239,77,183,21,36]},"ciphertext":{"type":"Buffer","data":[75,104,205,95,93,108,18,50,220,120,164,224,42,214,75,28]},"mac":{"type":"Buffer","data":[63,243,230,143,99,187,246,241,194,10,247,215,188,163,82,98,140,15,186,158,58,207,170,49,230,143,26,17,117,248,195,143]}}
Decrypted message: msg
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句