<p>There is no encryption involved anywhere in a blockchain. There are no keys to encrypt with, as every node has the same information as all others. Cryptography is involved, but for signing/proving. Not for encrypting.</p>

<p>Even in the zcash case, encryption is not involved. All wallets do is prove to the rest of the network that they had the funds they're spending. The only difference compared to Bitcoin is that it reveals less information in doing so, and as a result, the proofs are much more complex.</p>

<p><strong>blockchains</strong> don't generate private keys - that doesn't make sense, as the chain can be seen by everyone.</p>

<p><strong>Wallets</strong> do have private keys. They're never shared with anyone. They hand out the corresponding public keys in order to be paid, and use the private key to later prove to others they own certain coins.</p>

<p>The example you're describing with an exchange occurring between two chains is possible using a technique called <em>cross-chain atomic swap</em>. It relies on a hashlocked​ transaction where the first wallet that moves its money out on one chain reveals a random value that hashes to a value that is known ahead of time. The other party then uses this preimage to unlock funds on the other side.</p>

CC BY-SA 3.0
2017-03-15T14:07:04.643Z
2017-03-15T14:18:49.070Z
2017-03-15T14:18:49.070Z
Pieter Wuille
<p>Someone proposed something similar, posting encrypted files on IPFS network (public like say the Ethereum blockchain) and then sending keys to the participants to decrypt.  </p>

<p>The founder Juan Bennet highlighted the following quote:</p>

<p>'Naive example: encrypt the file with some secret, and share the secret with the people who have "read permission"'</p>

<p><a href="https://github.com/ipfs/ipfs/issues/86" rel="nofollow noreferrer">https://github.com/ipfs/ipfs/issues/86</a></p>

<p>What you really need is a decentralised capability system.</p>

<p><a href="https://github.com/autocontracts/permissioned-blocks/blob/master/whitepaper.md" rel="nofollow noreferrer">https://github.com/autocontracts/permissioned-blocks/blob/master/whitepaper.md</a></p>

<p>(Disclaimer, this is a white paper I wrote)</p>

CC BY-SA 3.0
2017-10-16T08:09:09.743Z
2017-10-16T08:09:09.743Z
Michael Smolenski
<p>It is not recommended to send a private asymmetric key as a blockchain transaction (which is a communication channel) in this manner. </p>

<p>There is a good paper on key exchanges here:</p>

<p><a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.216.6107&amp;rep=rep1&amp;type=pdf" rel="nofollow noreferrer">http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.216.6107&amp;rep=rep1&amp;type=pdf</a></p>

<p>In this paper the author makes also makes it clear that sending a private key over a channel is not good design:</p>

<p>"When a key is sent in a message, only the public key is used, to be
explicit... None of the protocols studied in this paper ever
send a secret key over the wire"</p>

<p><a href="https://dominictarr.github.io/secret-handshake-paper/shs.pdf" rel="nofollow noreferrer">https://dominictarr.github.io/secret-handshake-paper/shs.pdf</a></p>

<p>Public keys are designed for sending over a channel. Not the private key. Encryption can be broken by brute force. Once someone has the private key they can decrypt everything that was encrypted with that key.</p>

CC BY-SA 3.0
2017-10-15T21:58:44.557Z
Thanks for contributing but this answer doesn't provide enough detail to be useful
Highly Irregular
CC BY-SA 3.0
2017-10-16T07:54:37.980Z
I have updated my comment with some links.
Michael Smolenski
CC BY-SA 3.0
2017-10-16T21:40:17.443Z
This answer would be better if you explained that the blockchain is being used as a channel, and therefore the sources you cite are relevant.  This is difficult for a casual observer to pick up on, which is probably why you've been downvoted.
Jestin
CC BY-SA 3.0
2017-10-17T14:44:14.227Z
Thanks @Jestin. Yeah I was down voted before I put the links in explaining what I was meaning. First comment was "It is not recommended to send encrypted private keys over a channel" - without a reason. 

Up vote if you think the answer is better now :-)
Michael Smolenski
CC BY-SA 3.0
2017-10-17T15:02:56.223Z
The connection that is hard for people to make is `blockchain data == channel`.  It's a connection I think you've assumed people make, but I doubt they all do.  A sentence explaining this would help, especially since the term "channel" in this forum is more often used to mean "payment channel".
Jestin
CC BY-SA 3.0
2017-10-23T09:21:46.247Z
OK. Good point, I have updated. Please upvote.
Michael Smolenski
CC BY-SA 3.0
2017-10-15T16:56:17.993Z
2017-10-23T09:21:19.583Z
2017-10-23T09:21:19.583Z
Michael Smolenski
<p>Ok, I know that blockchain is public knowledge. But, than, there are experiments like zcash which encrypt sender receiver and amount information and they still work.</p>

<p>I'm considering whether p2p blockchain arbitration service is possible. For example, you want to exchange ETH for BTC. A blockchain generates 2 addresses, one of which is for BTC, other is for ETH. Once both addresses are funded, funds of both are forwarded to the recipients. To do this via blockchain, there should be a secure way to store and use private keys on blockchain.</p>

<p>Is this completely impossible, or are there any indications that one could do something like that?</p>

CC BY-SA 3.0
2017-03-15T13:41:42.180Z
related: [Is there a way to store and share a private key through blockchain?](http://bitcoin.stackexchange.com/q/52064/5406)
Murch
CC BY-SA 3.0
2017-03-17T00:32:49.130Z
Yes. There are examples of people attaching binary files into the blockchain. If you encrypt the private keys, then you can store them on the blockchain. If you use public key cryptography, encrypt it with someone's public key and only they can decrypt it. If you use symmetric key encryption, encrypt it with a password then tell someone the password. All of this is not recommended however.
Chloe
<blockchain><private-key><public-key><zcash>
Can private keys be securely stored on blockchain?
Arsen Zahray
# Can private keys be securely stored on blockchain?

(Asked by: username_0 on 2017-03-15)

Ok, I know that blockchain is public knowledge. But, than, there are experiments like zcash which encrypt sender receiver and amount information and they still work.

I'm considering whether p2p blockchain arbitration service is possible. For example, you want to exchange ETH for BTC. A blockchain generates 2 addresses, one of which is for BTC, other is for ETH. Once both addresses are funded, funds of both are forwarded to the recipients. To do this via blockchain, there should be a secure way to store and use private keys on blockchain.

Is this completely impossible, or are there any indications that one could do something like that?

**Tags:** blockchain, private-key, public-key, zcash

> **Comments:**
> **username_1**: related: [Is there a way to store and share a private key through blockchain?](http://bitcoin.stackexchange.com/q/52064/5406)  
> **username_2**: Yes. There are examples of people attaching binary files into the blockchain. If you encrypt the private keys, then you can store them on the blockchain. If you use public key cryptography, encrypt it with someone's public key and only they can decrypt it. If you use symmetric key encryption, encrypt it with a password then tell someone the password. All of this is not recommended however.  

---

## 3 answers

### Answer by username_3 on 2017-03-15. Score: 2 | Accepted answer

There is no encryption involved anywhere in a blockchain. There are no keys to encrypt with, as every node has the same information as all others. Cryptography is involved, but for signing/proving. Not for encrypting.

Even in the zcash case, encryption is not involved. All wallets do is prove to the rest of the network that they had the funds they're spending. The only difference compared to Bitcoin is that it reveals less information in doing so, and as a result, the proofs are much more complex.

**blockchains** don't generate private keys - that doesn't make sense, as the chain can be seen by everyone.

**Wallets** do have private keys. They're never shared with anyone. They hand out the corresponding public keys in order to be paid, and use the private key to later prove to others they own certain coins.

The example you're describing with an exchange occurring between two chains is possible using a technique called *cross-chain atomic swap*. It relies on a hashlocked​ transaction where the first wallet that moves its money out on one chain reveals a random value that hashes to a value that is known ahead of time. The other party then uses this preimage to unlock funds on the other side.


---

### Answer by username_4 on 2017-10-16. Score: 1

Someone proposed something similar, posting encrypted files on IPFS network (public like say the Ethereum blockchain) and then sending keys to the participants to decrypt.

The founder Juan Bennet highlighted the following quote:

'Naive example: encrypt the file with some secret, and share the secret with the people who have "read permission"'

<https://github.com/ipfs/ipfs/issues/86>

What you really need is a decentralised capability system.

<https://github.com/autocontracts/permissioned-blocks/blob/master/whitepaper.md>

(Disclaimer, this is a white paper I wrote)


---

### Answer by username_4 on 2017-10-15. Score: -1

It is not recommended to send a private asymmetric key as a blockchain transaction (which is a communication channel) in this manner.

There is a good paper on key exchanges here:

<http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.216.6107&rep=rep1&type=pdf>

In this paper the author makes also makes it clear that sending a private key over a channel is not good design:

"When a key is sent in a message, only the public key is used, to be
explicit... None of the protocols studied in this paper ever
send a secret key over the wire"

<https://dominictarr.github.io/secret-handshake-paper/shs.pdf>

Public keys are designed for sending over a channel. Not the private key. Encryption can be broken by brute force. Once someone has the private key they can decrypt everything that was encrypted with that key.

> **Comments:**
> **username_5**: Thanks for contributing but this answer doesn't provide enough detail to be useful  
> **username_4**: I have updated my comment with some links.  
> **username_6**: This answer would be better if you explained that the blockchain is being used as a channel, and therefore the sources you cite are relevant.  This is difficult for a casual observer to pick up on, which is probably why you've been downvoted.  
> **username_4**: Thanks @username_6. Yeah I was down voted before I put the links in explaining what I was meaning. First comment was "It is not recommended to send encrypted private keys over a channel" - without a reason.   Up vote if you think the answer is better now :-)  
> **username_6**: The connection that is hard for people to make is `blockchain data == channel`.  It's a connection I think you've assumed people make, but I doubt they all do.  A sentence explaining this would help, especially since the term "channel" in this forum is more often used to mean "payment channel".  
> **username_4**: OK. Good point, I have updated. Please upvote.  

---

