Bmng dev master #687

Merged
Atheros1 merged 12 commits from bmng-dev-master into master 2014-07-15 01:42:36 +02:00
Showing only changes of commit 9b40838f25 - Show all commits

View File

@ -1,9 +1,10 @@
import pyelliptic import pyelliptic
from pyelliptic import arithmetic as a, OpenSSL from pyelliptic import arithmetic as a, OpenSSL
def makeCryptor(privkey): def makeCryptor(privkey):
privkey_bin = '\x02\xca\x00 '+a.changebase(privkey,16,256,minlen=32) private_key = a.changebase(privkey, 16, 256, minlen=32)
pubkey = a.changebase(a.privtopub(privkey),16,256,minlen=65)[1:] public_key = pointMult(private_key)
pubkey_bin = '\x02\xca\x00 '+pubkey[:32]+'\x00 '+pubkey[32:] privkey_bin = '\x02\xca\x00\x20' + private_key
pubkey_bin = '\x02\xca\x00\x20' + public_key[1:-32] + '\x00\x20' + pubkey[-32:]
cryptor = pyelliptic.ECC(curve='secp256k1',privkey=privkey_bin,pubkey=pubkey_bin) cryptor = pyelliptic.ECC(curve='secp256k1',privkey=privkey_bin,pubkey=pubkey_bin)
return cryptor return cryptor
def hexToPubkey(pubkey): def hexToPubkey(pubkey):
@ -15,7 +16,9 @@ def makePubCryptor(pubkey):
return pyelliptic.ECC(curve='secp256k1',pubkey=pubkey_bin) return pyelliptic.ECC(curve='secp256k1',pubkey=pubkey_bin)
# Converts hex private key into hex public key # Converts hex private key into hex public key
def privToPub(privkey): def privToPub(privkey):
return a.privtopub(privkey) private_key = a.changebase(privkey, 16, 256, minlen=32)
public_key = pointMult(private_key)
return public_key.encode('hex')
# Encrypts message with hex public key # Encrypts message with hex public key
def encrypt(msg,hexPubkey): def encrypt(msg,hexPubkey):
return pyelliptic.ECC(curve='secp256k1').encrypt(msg,hexToPubkey(hexPubkey)) return pyelliptic.ECC(curve='secp256k1').encrypt(msg,hexToPubkey(hexPubkey))