Bitcoin Forum
May 04, 2024, 08:32:16 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Encrypt/decrypt arbitrary text using bitcoin keys!  (Read 4672 times)
phelix (OP)
Legendary
*
Offline Offline

Activity: 1708
Merit: 1019



View Profile
February 19, 2013, 08:10:46 AM
Last edit: February 19, 2013, 08:28:06 AM by phelix
 #1

It is possible to encrypt/decrypt messages with the bitcoin keys.

Maybe you are aware of the PyBitmessage project by Atheros: https://bitcointalk.org/index.php?topic=128230

Its code can be used to do this:

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from highlevelcrypto import *
from pyelliptic import arithmetic
from binascii import hexlify, unhexlify

# msg
plaintext = "Bitcoin is the new world currency."

# from Casascius btc utility
privkeyUtil = "0x29635CB46E2AA93EFF403448E1555DC99F4ECB75898BBF232D769EA5C029A1DF"
pubkeyUtil = "0x04AAC5327CEF4681FEDCA19C5D9C009172484A3497B616376947E81F2E9ED35968A707D3C4966AB49608F047A5F9E29D16ABD35FB4F613D5B5A119EBDD6799C45D"
pubkeyHashUtil = "702B9096868BA888D71326D1F55EC2B20CB84D3A"
addressUtil = "1BE6sRNQgQ28iiYPKBXeyHh1E6LPAdaxfH"

################################################################
# actual work
################################################################
pubkeyEcc = privToPub(privkeyUtil[2:]).upper()
cipher = encrypt(plaintext, pubkeyEcc)
match = bool(decrypt(cipher, privkeyUtil[2:]) == plaintext)
################################################################

# output
print "keys------------"
print "data from Casascius utility"
print "privkey:", privkeyUtil
print "pubkey:", pubkeyUtil
print "address:", addressUtil
print

print "data generated from above privkey with PyBitmessage highlevelcrypto (pyelliptic / openSSL)"

print "pubkey:", pubkeyEcc
print "address:", arithmetic.pubkey_to_address(pubkeyEcc)
print

print "encryption------------"

print "plaintext:", plaintext
print "cipher:", hexlify(cipher)

if match:
    print "decrypt: match"


#output:
##keys------------
##data from Casascius utility
##privkey: 0x29635CB46E2AA93EFF403448E1555DC99F4ECB75898BBF232D769EA5C029A1DF
##pubkey: 0x04AAC5327CEF4681FEDCA19C5D9C009172484A3497B616376947E81F2E9ED35968A707D3C4966AB49608F047A5F9E29D16ABD35FB4F613D5B5A119EBDD6799C45D
##address: 1BE6sRNQgQ28iiYPKBXeyHh1E6LPAdaxfH
##
##data generated from above privkey with PyBitmessage highlevelcrypto (pyelliptic / openSSL)
##pubkey: 04AAC5327CEF4681FEDCA19C5D9C009172484A3497B616376947E81F2E9ED35968A707D3C4966AB49608F047A5F9E29D16ABD35FB4F613D5B5A119EBDD6799C45D
##address: 1BE6sRNQgQ28iiYPKBXeyHh1E6LPAdaxfH
##
##encryption------------
##plaintext: Bitcoin is the new world currency.
##cipher: f8f358b861c041e430024ecbecccaada02ca00203c00513c46364b3f08de80b202e658155093dfd6f0847daff53295a858aafb2000205fef717e5e6935a450930925d8da7aecd02a560a4f8c5ebdad1517e8480724b8fb6fb42db52256c14df788546bd32360604f9cb0ad6ce79d8e98274e54a55526baceb8d559e854f75300114d0148d310d70ad7515e8f8f2e81a416d93d26a4f06d185c69bd64a2384303e9fff393a8ee
##decrypt: match
[/quote]


I am not a cryptographer but from what I understand it should be possible to make this really secure (not sure about the state of the libraries at hand).
Be very wary of relying on JavaScript for security on crypto sites. The site can change the JavaScript at any time unless you take unusual precautions, and browsers are not generally known for their airtight security.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714811536
Hero Member
*
Offline Offline

Posts: 1714811536

View Profile Personal Message (Offline)

Ignore
1714811536
Reply with quote  #2

1714811536
Report to moderator
phelix (OP)
Legendary
*
Offline Offline

Activity: 1708
Merit: 1019



View Profile
February 19, 2013, 08:29:36 AM
 #2

Well it is public and private key encryption this is the bread and butter of SSL and TLS. So yes is extremely secure.

 Grin
Insu Dra
Full Member
***
Offline Offline

Activity: 182
Merit: 100



View Profile
February 19, 2013, 11:02:29 AM
 #3

Well it is public and private key encryption this is the bread and butter of SSL and TLS. So yes is extremely secure.

it is posible but lets take that idea one step further ?

The issue with ssl is that you need to send public key from a server to the client. Having these key's stored in a block chain would make the whole system a lot more secure sins it would become nearly impossible for a man in the middle to send false key's to a client that checks a block chain for valid keys. At the same time it would would eliminate the all powerful CA's that have been know to hide and/or deny hacks and leaked private key's. Yes / No ?

If only I had time/knowledge to implement something like that ... but a man can dream right.

"drugs, guns, and gambling for anyone and everyone!"
phelix (OP)
Legendary
*
Offline Offline

Activity: 1708
Merit: 1019



View Profile
February 19, 2013, 01:20:30 PM
 #4

Well it is public and private key encryption this is the bread and butter of SSL and TLS. So yes is extremely secure.

it is posible but lets take that idea one step further ?

The issue with ssl is that you need to send public key from a server to the client. Having these key's stored in a block chain would make the whole system a lot more secure sins it would become nearly impossible for a man in the middle to send false key's to a client that checks a block chain for valid keys. At the same time it would would eliminate the all powerful CA's that have been know to hide and/or deny hacks and leaked private key's. Yes / No ?
it has been thought about it for namecoin a long time ago. Only now do I realize that it could be done directly with the namecoin keys.

there is even a small bounty available for implementing it: https://bitcointalk.org/index.php?topic=117795

Quote
If only I had time/knowledge to implement something like that ... but a man can dream right.
+1 Smiley
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!