Pop-up Window How to encrypt messages with Pub/Priv keys - NTV News 🔥

admolo

Display

See it

____

How to encrypt messages with Pub/Priv keys

I'm wondering if it's possible to use the Bitcoin public and private keys (usually used for signing) for text encryption. This is an example in nodeJs:

import pkg from 'bitcore-lib'

const { PrivateKey, Networks } = pkg
const privateKey = new PrivateKey(Networks['livenet'])
const myObject = {
    privateKey: privateKey,
    P2PKHAddress: privateKey.toAddress(),
    publicKey: privateKey.toPublicKey(),
    wif: privateKey.toWIF()
}

It is possible to use publicKey to encrypt a message and decrypt with privateKey?

const encryptedText = encrypt('Hello', publicKey)
const decryptedText = decrypt(encryptedText, privateKey)

assert decryptedText === 'Hello'



from Recent Questions - Bitcoin Stack Exchange
October 22, 2022 at 12:40AM

Related Posts

Subscribe Our Newsletter
close