You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import base64
import win32api
from PyQt5 . QtWidgets import QMessageBox
from pyDes import *
import binascii
import os
import sys
class Register :
def __init__ ( self ) :
self . Des_Key = b " BHC#@*AW " # Key( 可换)
self . Des_IV = b " \x22 \x33 \x35 \x81 \xBC \x38 \x5A \xE7 " # 自定义IV向量( 可换)
self . str = self . getCVolumeSerialNumber ( )
# 获取C盘卷序列号
def getCVolumeSerialNumber ( self ) :
CVolumeSerialNumber = win32api . GetVolumeInformation ( " C: \\ " ) [ 1 ]
# print(CVolumeSerialNumber)
if CVolumeSerialNumber :
return str ( CVolumeSerialNumber )
else :
return 0
# 使用DES加base64的形式加密
def DesEncrypt ( self ) :
k = des ( self . Des_Key , CBC , self . Des_IV , pad = None , padmode = PAD_PKCS5 )
EncryptStr = k . encrypt ( self . str )
return base64 . b64encode ( EncryptStr ) # 转base64编码返回
# 获取注册码,验证
def regist ( self , key ) :
key = key
self . str1 = base64 . b64decode ( key )
if key :
content = self . getCVolumeSerialNumber ( )
key_decrypted = str ( self . DesDecrypt ( ) )
if content != 0 and key_decrypted != 0 :
if content != key_decrypted :
return False
elif content == key_decrypted :
return True
else :
return False
else :
return False
else :
return False
return False
# des解码
def DesDecrypt ( self ) :
k = des ( self . Des_Key , CBC , self . Des_IV , pad = None , padmode = PAD_PKCS5 )
DecryptStr = k . decrypt ( self . str1 )
return DecryptStr . decode ( ' utf-8 ' )
def checkLicense ( self ) :
if os . path . isfile ( ' static/license.lic ' ) :
with open ( ' static/license.lic ' , ' r ' ) as f :
key = f . read ( )
if self . regist ( key ) :
return True
else :
return False
else :
return False