我们可以使用加密钱包的 public 地址和私钥来加密文件吗?

Could we use public address and private key of a crypto wallet to encrypt a file?

就像我可以通过从我的钱包中使用一个私钥来解密它而不是使用 GPG 来将完全加密的文件存储在 IPFS 和区块链中一样。我只是想知道这是否可能。

可以,但总的来说,我不建议这样做,因为密钥通常是一次性使用的。大多数钱包不会重复使用密钥,它们会为每笔交易生成新密钥,以保护隐私。

但是,对于比特币,您可以使用类似这样的东西 eccrypto(请自行研究此实现的安全性)。

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