Rev445, Fix and test random fail in CryptMessage decrypt
This commit is contained in:
parent
8aa4e27938
commit
64e5e0c80e
3 changed files with 39 additions and 7 deletions
|
@ -1,13 +1,13 @@
|
|||
import hashlib
|
||||
import base64
|
||||
import binascii
|
||||
import struct
|
||||
|
||||
import lib.pybitcointools as btctools
|
||||
from util import ThreadPool
|
||||
from Crypt import Crypt
|
||||
|
||||
ecc_cache = {}
|
||||
|
||||
|
||||
def eciesEncrypt(data, pubkey, ephemcurve=None, ciphername='aes-256-cbc'):
|
||||
from lib import pyelliptic
|
||||
pubkey_openssl = toOpensslPublickey(base64.b64decode(pubkey))
|
||||
|
@ -32,7 +32,7 @@ def eciesDecryptMulti(encrypted_datas, privatekey):
|
|||
try:
|
||||
text = eciesDecrypt(encrypted_data, privatekey).decode("utf8")
|
||||
texts.append(text)
|
||||
except:
|
||||
except Exception:
|
||||
texts.append(None)
|
||||
return texts
|
||||
|
||||
|
@ -41,9 +41,26 @@ def eciesDecrypt(encrypted_data, privatekey):
|
|||
ecc_key = getEcc(privatekey)
|
||||
return ecc_key.decrypt(base64.b64decode(encrypted_data))
|
||||
|
||||
|
||||
def decodePubkey(pubkey):
|
||||
i = 0
|
||||
curve = struct.unpack('!H', pubkey[i:i + 2])[0]
|
||||
i += 2
|
||||
tmplen = struct.unpack('!H', pubkey[i:i + 2])[0]
|
||||
i += 2
|
||||
pubkey_x = pubkey[i:i + tmplen]
|
||||
i += tmplen
|
||||
tmplen = struct.unpack('!H', pubkey[i:i + 2])[0]
|
||||
i += 2
|
||||
pubkey_y = pubkey[i:i + tmplen]
|
||||
i += tmplen
|
||||
return curve, pubkey_x, pubkey_y, i
|
||||
|
||||
|
||||
def split(encrypted):
|
||||
iv = encrypted[0:16]
|
||||
ciphertext = encrypted[16 + 70:-32]
|
||||
curve, pubkey_x, pubkey_y, i = decodePubkey(encrypted[16:])
|
||||
ciphertext = encrypted[16 + i:-32]
|
||||
|
||||
return iv, ciphertext
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue