1a883ccb by 冯轩

Merge branch 'feature/CHINARPA-5092'

2 parents 6349bed3 2a689f4f
...@@ -48,7 +48,8 @@ from apps.doc.ocr.cms import cms ...@@ -48,7 +48,8 @@ from apps.doc.ocr.cms import cms
48 from apps.doc.exceptions import GCAPException 48 from apps.doc.exceptions import GCAPException
49 from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType, SystemName 49 from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType, SystemName
50 from common.tools.comparison import cp 50 from common.tools.comparison import cp
51 from common.tools.des import decode_des 51 # from common.tools.des import decode_des
52 from common.tools.aes_util import aes_decrypt_cbc
52 53
53 import threading 54 import threading
54 import concurrent.futures 55 import concurrent.futures
...@@ -62,6 +63,7 @@ log_base = '[Compare]' ...@@ -62,6 +63,7 @@ log_base = '[Compare]'
62 empty_str = '' 63 empty_str = ''
63 empty_error_type = 1000 64 empty_error_type = 1000
64 des_key = conf.CMS_DES_KEY 65 des_key = conf.CMS_DES_KEY
66 des_iv = conf.CMS_DES_IV
65 67
66 68
67 def rotate_bound(image, angle): 69 def rotate_bound(image, angle):
...@@ -985,7 +987,7 @@ def get_se_cms_compare_info_auto(application_id, last_obj, application_entity, d ...@@ -985,7 +987,7 @@ def get_se_cms_compare_info_auto(application_id, last_obj, application_entity, d
985 if id_info.get('idType') in consts.SE_CMS_FIRST_ID_FIELD_MAPPING: 987 if id_info.get('idType') in consts.SE_CMS_FIRST_ID_FIELD_MAPPING:
986 license_en, is_prc = consts.SE_CMS_FIRST_ID_FIELD_MAPPING[id_info['idType']] 988 license_en, is_prc = consts.SE_CMS_FIRST_ID_FIELD_MAPPING[id_info['idType']]
987 # ['customerName', 'idNum', 'dateOfBirth', 'idExpiryDate', 'hukouProvince'] 989 # ['customerName', 'idNum', 'dateOfBirth', 'idExpiryDate', 'hukouProvince']
988 id_num = decode_des(id_info.get('idNum', ''), des_key) 990 id_num = aes_decrypt_cbc(id_info.get('idNum', ''), des_key, des_iv)
989 field_input = [('customerName', customer_name), ('idNum', id_num), 991 field_input = [('customerName', customer_name), ('idNum', id_num),
990 ('idExpiryDate', id_info.get('idExpiryDate', ''))] 992 ('idExpiryDate', id_info.get('idExpiryDate', ''))]
991 # if is_prc: 993 # if is_prc:
...@@ -997,7 +999,7 @@ def get_se_cms_compare_info_auto(application_id, last_obj, application_entity, d ...@@ -997,7 +999,7 @@ def get_se_cms_compare_info_auto(application_id, last_obj, application_entity, d
997 elif id_info.get('idType') in ['Unified Social Credit Code', 'Tax Number', 'Business License Number']: 999 elif id_info.get('idType') in ['Unified Social Credit Code', 'Tax Number', 'Business License Number']:
998 # ['companyName', 'legalRepName', 'businessLicenseNo', 'organizationCreditCode', 1000 # ['companyName', 'legalRepName', 'businessLicenseNo', 'organizationCreditCode',
999 # 'taxRegistrationCertificateNo', 'establishmentDate', 'businessLicenseDueDate'] 1001 # 'taxRegistrationCertificateNo', 'establishmentDate', 'businessLicenseDueDate']
1000 id_num = decode_des(id_info.get('idNum', ''), des_key) 1002 id_num = aes_decrypt_cbc(id_info.get('idNum', ''), des_key, des_iv)
1001 bl_field_input = [ 1003 bl_field_input = [
1002 ('companyName', customer_name), 1004 ('companyName', customer_name),
1003 ('legalRepName', legal_name), 1005 ('legalRepName', legal_name),
...@@ -1186,7 +1188,7 @@ def get_se_cms_compare_info_auto(application_id, last_obj, application_entity, d ...@@ -1186,7 +1188,7 @@ def get_se_cms_compare_info_auto(application_id, last_obj, application_entity, d
1186 # 银行卡------------------------------------------------------------------------------------------------------- 1188 # 银行卡-------------------------------------------------------------------------------------------------------
1187 bank_info = {} 1189 bank_info = {}
1188 bank_name = cms_info.get('bankAccountDetails', {}).get('bankName', '') 1190 bank_name = cms_info.get('bankAccountDetails', {}).get('bankName', '')
1189 account_no = decode_des(cms_info.get('bankAccountDetails', {}).get('accountNo', ''), des_key) 1191 account_no = aes_decrypt_cbc(cms_info.get('bankAccountDetails', {}).get('accountNo', ''), des_key, des_iv)
1190 account_holder_name = cms_info.get('bankAccountDetails', {}).get('accountHolderName', '') 1192 account_holder_name = cms_info.get('bankAccountDetails', {}).get('accountHolderName', '')
1191 is_gsyh = True if '工商' in bank_name else False 1193 is_gsyh = True if '工商' in bank_name else False
1192 1194
...@@ -1676,7 +1678,7 @@ def get_se_cms_compare_info(application_id, last_obj, application_entity, detect ...@@ -1676,7 +1678,7 @@ def get_se_cms_compare_info(application_id, last_obj, application_entity, detect
1676 if id_info.get('idType') in consts.SE_CMS_FIRST_ID_FIELD_MAPPING: 1678 if id_info.get('idType') in consts.SE_CMS_FIRST_ID_FIELD_MAPPING:
1677 license_en, is_prc = consts.SE_CMS_FIRST_ID_FIELD_MAPPING[id_info['idType']] 1679 license_en, is_prc = consts.SE_CMS_FIRST_ID_FIELD_MAPPING[id_info['idType']]
1678 # ['customerName', 'idNum', 'dateOfBirth', 'idExpiryDate', 'hukouProvince'] 1680 # ['customerName', 'idNum', 'dateOfBirth', 'idExpiryDate', 'hukouProvince']
1679 id_num = decode_des(id_info.get('idNum', ''), des_key) 1681 id_num = aes_decrypt_cbc(id_info.get('idNum', ''), des_key, des_iv)
1680 field_input = [('customerName', customer_name), ('idNum', id_num), 1682 field_input = [('customerName', customer_name), ('idNum', id_num),
1681 ('idExpiryDate', id_info.get('idExpiryDate', ''))] 1683 ('idExpiryDate', id_info.get('idExpiryDate', ''))]
1682 # if is_prc: 1684 # if is_prc:
...@@ -1688,7 +1690,7 @@ def get_se_cms_compare_info(application_id, last_obj, application_entity, detect ...@@ -1688,7 +1690,7 @@ def get_se_cms_compare_info(application_id, last_obj, application_entity, detect
1688 elif id_info.get('idType') in ['Unified Social Credit Code', 'Tax Number', 'Business License Number']: 1690 elif id_info.get('idType') in ['Unified Social Credit Code', 'Tax Number', 'Business License Number']:
1689 # ['companyName', 'legalRepName', 'businessLicenseNo', 'organizationCreditCode', 1691 # ['companyName', 'legalRepName', 'businessLicenseNo', 'organizationCreditCode',
1690 # 'taxRegistrationCertificateNo', 'establishmentDate', 'businessLicenseDueDate'] 1692 # 'taxRegistrationCertificateNo', 'establishmentDate', 'businessLicenseDueDate']
1691 id_num = decode_des(id_info.get('idNum', ''), des_key) 1693 id_num = aes_decrypt_cbc(id_info.get('idNum', ''), des_key, des_iv)
1692 bl_field_input = [ 1694 bl_field_input = [
1693 ('companyName', customer_name), 1695 ('companyName', customer_name),
1694 ('legalRepName', legal_name), 1696 ('legalRepName', legal_name),
...@@ -1877,7 +1879,7 @@ def get_se_cms_compare_info(application_id, last_obj, application_entity, detect ...@@ -1877,7 +1879,7 @@ def get_se_cms_compare_info(application_id, last_obj, application_entity, detect
1877 # 银行卡------------------------------------------------------------------------------------------------------- 1879 # 银行卡-------------------------------------------------------------------------------------------------------
1878 bank_info = {} 1880 bank_info = {}
1879 bank_name = cms_info.get('bankAccountDetails', {}).get('bankName', '') 1881 bank_name = cms_info.get('bankAccountDetails', {}).get('bankName', '')
1880 account_no = decode_des(cms_info.get('bankAccountDetails', {}).get('accountNo', ''), des_key) 1882 account_no = aes_decrypt_cbc(cms_info.get('bankAccountDetails', {}).get('accountNo', ''), des_key, des_iv)
1881 account_holder_name = cms_info.get('bankAccountDetails', {}).get('accountHolderName', '') 1883 account_holder_name = cms_info.get('bankAccountDetails', {}).get('accountHolderName', '')
1882 is_gsyh = True if '工商' in bank_name else False 1884 is_gsyh = True if '工商' in bank_name else False
1883 1885
......
1 #这个有问题
2 from Crypto.Cipher import AES
3 from base64 import b64encode, b64decode
4
5
6 def encrypt_ecb(data, key):
7 data = data.encode()
8 key = key.encode()
9 aes = AES.new(key, AES.MODE_CBC, bytes(16))
10 res = aes.encrypt(pad(data, 32))
11 return b64encode(res).decode()
12
13
14 def decrypt(data, key, iv):
15 key = key.encode()
16 iv = iv.encode()
17 # aes = AES.new(key, AES.MODE_CBC, bytes(16))
18 aes = AES.new(key, AES.MODE_CBC, iv)
19 res = aes.decrypt(b64decode(data))
20 return unpad(res, 32).decode()
21
22
23 def unpad(padded_data, block_size, style='pkcs7'):
24 pdata_len = len(padded_data)
25 if pdata_len == 0:
26 raise ValueError("Zero-length input cannot be unpadded")
27 if pdata_len % block_size:
28 raise ValueError("Input data is not padded")
29 if style in ('pkcs7', 'x923'):
30 padding_len = bord(padded_data[-1])
31 if padding_len<1 or padding_len>min(block_size, pdata_len):
32 raise ValueError("Padding is incorrect.")
33 if style == 'pkcs7':
34 if padded_data[-padding_len:]!=bchr(padding_len)*padding_len:
35 raise ValueError("PKCS#7 padding is incorrect.")
36 else:
37 if padded_data[-padding_len:-1]!=bchr(0)*(padding_len-1):
38 raise ValueError("ANSI X.923 padding is incorrect.")
39 elif style == 'iso7816':
40 padding_len = pdata_len - padded_data.rfind(bchr(128))
41 if padding_len<1 or padding_len>min(block_size, pdata_len):
42 raise ValueError("Padding is incorrect.")
43 if padding_len>1 and padded_data[1-padding_len:]!=bchr(0)*(padding_len-1):
44 raise ValueError("ISO 7816-4 padding is incorrect.")
45 else:
46 raise ValueError("Unknown padding style")
47 return padded_data[:-padding_len]
48
49 def pad(data_to_pad, block_size, style='pkcs7'):
50 padding_len = block_size-len(data_to_pad)%block_size
51 if style == 'pkcs7':
52 padding = bchr(padding_len)*padding_len
53 elif style == 'x923':
54 padding = bchr(0)*(padding_len-1) + bchr(padding_len)
55 elif style == 'iso7816':
56 padding = bchr(128) + bchr(0)*(padding_len-1)
57 else:
58 raise ValueError("Unknown padding style")
59 return data_to_pad + padding
60
61 def bord(s):
62 return s
63 def bchr(s):
64 return bytes([s])
65
66 if __name__ == '__main__':
67
68 decrypt_data = decrypt('QkjNiuixpmtcxxqxaIZ30A==', 'm0XsOHC52YZ5KtakhpuMSZtF7DhwudmG', 'OCRocr2024UATocr')
69 print('解密:', decrypt_data)
...\ No newline at end of file ...\ No newline at end of file
1 from Crypto.Cipher import AES
2 from base64 import b64encode, b64decode
3
4 def aes_encrypt_cbc(data, key, iv):
5 cipher = AES.new(key, AES.MODE_CBC, iv)
6 return cipher.encrypt(data)
7
8 def aes_decrypt_cbc(data, key, iv):
9 res = ''
10 try:
11 cipher = AES.new(key.encode(), AES.MODE_CBC, iv.encode())
12 res = cipher.decrypt(b64decode(data))
13 res = res.decode('utf-8').replace('\x0e', '').replace('\u007', '')
14 except Exception as e:
15 res = ''
16 return res
17
18
19 # 示例使用
20 key = 'm0XsOHC52YZ5KtakhpuMSZtF7DhwudmG' # 密钥长度必须是16、24或32字节
21 iv = 'OCRocr2024UATocr'
22 decrypted_data = aes_decrypt_cbc('QkjNiuixpmtcxxqxaIZ30A==', key, iv)
23 print("解密:", decrypted_data)
...\ No newline at end of file ...\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!