#14 Enhancement: pycrypto was deprecated, use pycryptodome instead.

This commit is contained in:
codezjx 2018-09-12 19:46:01 +08:00
parent 2849de3dc1
commit 7aeeb2c1c3
3 changed files with 6 additions and 6 deletions

View File

@ -4,7 +4,7 @@ import os
import base64 import base64
import json import json
import binascii import binascii
from Crypto.Cipher import AES from Cryptodome.Cipher import AES
from ncm.constants import modulus, nonce, pub_key from ncm.constants import modulus, nonce, pub_key
@ -12,7 +12,7 @@ from ncm.constants import modulus, nonce, pub_key
def encrypted_request(text): def encrypted_request(text):
text = json.dumps(text) text = json.dumps(text)
sec_key = create_secret_key(16) sec_key = create_secret_key(16)
enc_text = aes_encrypt(aes_encrypt(text, nonce), sec_key) enc_text = aes_encrypt(aes_encrypt(text, nonce), sec_key.decode('utf-8'))
enc_sec_key = rsa_encrypt(sec_key, pub_key, modulus) enc_sec_key = rsa_encrypt(sec_key, pub_key, modulus)
data = {'params': enc_text, 'encSecKey': enc_sec_key} data = {'params': enc_text, 'encSecKey': enc_sec_key}
return data return data
@ -21,8 +21,8 @@ def encrypted_request(text):
def aes_encrypt(text, sec_key): def aes_encrypt(text, sec_key):
pad = 16 - len(text) % 16 pad = 16 - len(text) % 16
text = text + chr(pad) * pad text = text + chr(pad) * pad
encryptor = AES.new(sec_key, 2, '0102030405060708') encryptor = AES.new(sec_key.encode('utf-8'), AES.MODE_CBC, b'0102030405060708')
cipher_text = encryptor.encrypt(text) cipher_text = encryptor.encrypt(text.encode('utf-8'))
cipher_text = base64.b64encode(cipher_text).decode('utf-8') cipher_text = base64.b64encode(cipher_text).decode('utf-8')
return cipher_text return cipher_text

View File

@ -1,4 +1,4 @@
requests>=2.17.3 requests>=2.17.3
pycrypto>=2.6.1 pycryptodomex
mutagen>=1.38.0 mutagen>=1.38.0
Pillow>=4.3.0 Pillow>=4.3.0

View File

@ -7,7 +7,7 @@ setup(
packages=find_packages(), packages=find_packages(),
install_requires=[ install_requires=[
'requests>=2.17.3', 'requests>=2.17.3',
'pycrypto>=2.6.1', 'pycryptodomex',
'mutagen>=1.38.0', 'mutagen>=1.38.0',
'Pillow>=4.3.0', 'Pillow>=4.3.0',
], ],