sydomain

思绪来的快,去的也快,偶尔在这里停留。

python绑定cpu序列号并对序列号进行加密配合到期时间

import sys
from datetime import datetime, timedelta
import tkinter as tk
from tkinter import messagebox
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes

# 加密密钥,必须是16、24或32字节长
key = b'ThisIsASecretKey'

def encrypt_cpu_serial(cpu_serial):
    cipher = AES.new(key, AES.MODE_ECB)
    encrypted_cpu_serial = cipher.encrypt(pad(cpu_serial.encode(), AES.block_size))
    return encrypted_cpu_serial

def decrypt_cpu_serial(encrypted_cpu_serial):
    cipher = AES.new(key, AES.MODE_ECB)
    decrypted_cpu_serial = unpad(cipher.decrypt(encrypted_cpu_serial), AES.block_size)
    return decrypted_cpu_serial.decode()

def check_expiry(expiry_date, encrypted_cpu_serial):
    current_date = datetime.now()
    expiry_date = datetime.strptime(expiry_date, "%Y-%m-%d %H:%M")

    if current_date < expiry_date:
        # 解密CPU序列号
        cpu_serial = decrypt_cpu_serial(encrypted_cpu_serial)

        # 检查CPU序列号是否匹配
        if cpu_serial == "BFEBFBFF000306A9":
            remaining_time = expiry_date - current_date
            remaining_days = remaining_time.days
            remaining_hours = remaining_time.seconds // 3600
            remaining_minutes = (remaining_time.seconds % 3600) // 60
            messagebox.showinfo("到期提醒", f"还有 {remaining_days} 天 {remaining_hours} 小时 {remaining_minutes} 分钟到期")
        else:
            messagebox.showwarning("到期提醒", "设备未授权,请联系客服")
            sys.exit(1)
    elif current_date == expiry_date:
        messagebox.showinfo("到期提醒", "今天到期")
    else:
        messagebox.showwarning("到期提醒", "已过期,请联系客服充值\n wx:13888888888")
        sys.exit(1)  # 使用非零状态码表示程序异常退出

expiry_date = "2024-02-08 12:30"
cpu_serial = "BFEBFBFF000306A9"

# 加密CPU序列号
encrypted_cpu_serial = encrypt_cpu_serial(cpu_serial)

check_expiry(expiry_date, encrypted_cpu_serial)

在上述示例中,我们使用AES加密算法和ECB模式对CPU序列号进行加密和解密。加密密钥key必须是16、24或32字节长。您可以根据需要修改加密密钥。

Powered By sydomain

Copyright Your WebSite.Some Rights Reserved.