-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgold.py
More file actions
41 lines (32 loc) · 1.25 KB
/
gold.py
File metadata and controls
41 lines (32 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import base64
import logging
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives import hashes, serialization
logger = logging.getLogger(__name__)
def get_gold_donate_code(unique_addr: str, key_path: str = "key.pem"):
"""
Generate gold donate code using RSA512 signature (PKCS#1 v1.5 + SHA256)
"""
# --------- VB 中用于 VerifyData 的原始字符串 ---------
data = f"Gold|0|{unique_addr.replace('-', '')}".encode()
# --------- 从 PEM 中加载私钥 ---------
logger.info("loading RSA private key from %s...", key_path)
try:
with open(key_path, "rb") as f:
private_key = serialization.load_pem_private_key(
f.read(),
password=None
)
except Exception as e:
logger.exception("failed to load RSA private key")
raise e
# --------- 生成签名(PKCS#1 v1.5 + SHA256)---------
logger.info("generating signature...")
signature = private_key.sign(
data,
padding.PKCS1v15(),
hashes.SHA256()
)
sign_base64 = base64.b64encode(signature).decode()
logger.info("successfully got *gold* donate code (rsa512 sign): \n\n%s\n", sign_base64)
return sign_base64