Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,10 +68,13 @@ def sign_payload():
|
|
| 68 |
"""
|
| 69 |
Generate RSA-SHA256 signature for a given string payload.
|
| 70 |
Body: { "payload": "string-to-sign" }
|
| 71 |
-
Returns: { "
|
| 72 |
"""
|
| 73 |
try:
|
| 74 |
-
import
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
data = request.get_json(force=True)
|
| 77 |
payload = data.get("payload", "")
|
|
@@ -79,30 +82,19 @@ def sign_payload():
|
|
| 79 |
if not payload:
|
| 80 |
return jsonify({"error": "Missing 'payload' field"}), 400
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
h = SHA256.new(payload.encode())
|
| 96 |
-
signature = pkcs1_15.new(crypto_key).sign(h)
|
| 97 |
-
signature_b64 = base64.b64encode(signature).decode()
|
| 98 |
-
return jsonify({"signature": signature_b64}), 200
|
| 99 |
-
|
| 100 |
-
# ✅ Sign using rsa library (PKCS#1 v1.5)
|
| 101 |
-
signature = rsa.sign(payload.encode(), priv_key, 'SHA-256')
|
| 102 |
-
signature_b64 = base64.b64encode(signature).decode()
|
| 103 |
-
|
| 104 |
-
print("✅ Generated signature for:", payload)
|
| 105 |
-
return jsonify({"signature": signature_b64}), 200
|
| 106 |
|
| 107 |
except Exception as e:
|
| 108 |
print("🔥 Error generating signature:", str(e))
|
|
|
|
| 68 |
"""
|
| 69 |
Generate RSA-SHA256 signature for a given string payload.
|
| 70 |
Body: { "payload": "string-to-sign" }
|
| 71 |
+
Returns: { "sign": "base64_signature" }
|
| 72 |
"""
|
| 73 |
try:
|
| 74 |
+
import base64
|
| 75 |
+
from Crypto.PublicKey import RSA
|
| 76 |
+
from Crypto.Signature import pkcs1_15
|
| 77 |
+
from Crypto.Hash import SHA256
|
| 78 |
|
| 79 |
data = request.get_json(force=True)
|
| 80 |
payload = data.get("payload", "")
|
|
|
|
| 82 |
if not payload:
|
| 83 |
return jsonify({"error": "Missing 'payload' field"}), 400
|
| 84 |
|
| 85 |
+
# Load your PEM private key
|
| 86 |
+
private_key = RSA.import_key(PRIVATE_KEY)
|
| 87 |
+
|
| 88 |
+
# Compute SHA256 hash of the exact payload string
|
| 89 |
+
h = SHA256.new(payload.encode('utf-8'))
|
| 90 |
+
|
| 91 |
+
# Sign it
|
| 92 |
+
signature = pkcs1_15.new(private_key).sign(h)
|
| 93 |
+
|
| 94 |
+
# Return base64-encoded signature as 'sign' (what your custom action expects)
|
| 95 |
+
signature_b64 = base64.b64encode(signature).decode('utf-8')
|
| 96 |
+
|
| 97 |
+
return jsonify({"sign": signature_b64}), 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
except Exception as e:
|
| 100 |
print("🔥 Error generating signature:", str(e))
|