Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
@@ -7,30 +7,134 @@ sdk: docker
|
|
7 |
pinned: false
|
8 |
---
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
# Secure KeyLock Decoder API
|
11 |
|
12 |
-
This is a server-side API plugin running in a Docker container on Hugging Face Spaces. It provides a secure endpoint to decrypt messages from images created with the KeyLock application.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
20 |
|
21 |
---
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
-----BEGIN PUBLIC KEY-----
|
29 |
-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy2sWjB1iQ3vK03U7e/9E
|
30 |
-
O6J1K/s0tBq4Pz8F3r9/i8s7t9R1p8Z4Y6h4f4O7w9p9Z0c8t7m4J1e9g7K9m6f3
|
31 |
-
R1k3y7v1w0l7z6s5v2l8l4t9v8z7y6t5k2x1c9v7z3k1y9w8r5t3s1v9a8d7g6f5
|
32 |
-
e4d3c2b1a9f8e7d6c5b4a3f2e1d0c9b8a7f6e5d4c3b2a1f0e9d8c7b6a5f4e3d2
|
33 |
-
c1b0a9f8e7d6c5b4a3f2e1d0c9b8a7f6e5d4c3b2a1f0e9d8c7b6a5f4e3d2c1b0
|
34 |
-
a9f8e7d6c5b4a3f2e1d0c9b8a7f6e5d4c3b2a1f0e9d8c7b6a5f4e3d2c1b0a9f8
|
35 |
-
e7d6
|
36 |
-
-----END PUBLIC KEY-----
|
|
|
7 |
pinned: false
|
8 |
---
|
9 |
|
10 |
+
---
|
11 |
+
title: Secure KeyLock Decoder API
|
12 |
+
sdk: docker
|
13 |
+
app_port: 7860
|
14 |
+
colorFrom: pink
|
15 |
+
colorTo: pink
|
16 |
+
---
|
17 |
+
|
18 |
# Secure KeyLock Decoder API
|
19 |
|
20 |
+
This is a server-side API plugin running in a Docker container on Hugging Face Spaces. It provides a secure, public endpoint to decrypt messages from images created with the KeyLock steganography application.
|
21 |
+
|
22 |
+
The core purpose of this service is to act as a trusted third party that holds a secret key. Users can encrypt data using the corresponding public key, and this service will decrypt it for them, without the user ever needing to handle the private key themselves.
|
23 |
+
|
24 |
+
## Live API Status
|
25 |
+
|
26 |
+
You can check if the API is running by visiting the root of its direct URL:
|
27 |
+
|
28 |
+
- **Health Check:** **[https://broadfield-dev-keylock-rsa-js.hf.space/](https://broadfield-dev-keylock-rsa-js.hf.space/)**
|
29 |
+
|
30 |
+
If the server is running correctly, you will see a JSON response like #`{"status":"ok",...}`.
|
31 |
+
|
32 |
+
---
|
33 |
+
|
34 |
+
## How to Use This API
|
35 |
+
|
36 |
+
The process involves two main steps: encrypting the data into an image, and then sending that image to this API for decryption.
|
37 |
+
|
38 |
+
### Step 1: Encrypt Your Data
|
39 |
+
|
40 |
+
1. **Get the Public Key:** You must use this service's specific public key to encrypt your data. Any other key pair will result in a decryption error.
|
41 |
+
|
42 |
+
**Service Public Key:**
|
43 |
+
```pem
|
44 |
+
-----BEGIN PUBLIC KEY-----
|
45 |
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy2sWjB1iQ3vK03U7e/9E
|
46 |
+
O6J1K/s0tBq4Pz8F3r9/i8s7t9R1p8Z4Y6h4f4O7w9p9Z0c8t7m4J1e9g7K9m6f3
|
47 |
+
R1k3y7v1w0l7z6s5v2l8l4t9v8z7y6t5k2x1c9v7z3k1y9w8r5t3s1v9a8d7g6f5
|
48 |
+
e4d3c2b1a9f8e7d6c5b4a3f2e1d0c9b8a7f6e5d4c3b2a1f0e9d8c7b6a5f4e3d2
|
49 |
+
c1b0a9f8e7d6c5b4a3f2e1d0c9b8a7f6e5d4c3b2a1f0e9d8c7b6a5f4e3d2c1b0
|
50 |
+
a9f8e7d6c5b4a3f2e1d0c9b8a7f6e5d4c3b2a1f0e9d8c7b6a5f4e3d2c1b0a9f8
|
51 |
+
e7d6
|
52 |
+
-----END PUBLIC KEY-----
|
53 |
+
```
|
54 |
+
|
55 |
+
2. **Use an Encryption Tool:** Go to the [KeyLock RSA-BU](https://huggingface.co/spaces/broadfield-dev/KeyLock-RSA-BU) application (or use any compatible tool).
|
56 |
+
- On the "Embed Data" tab, enter your secret data (e.g., #`USERNAME: myuser`).
|
57 |
+
- Paste the **Service Public Key** from above into the "Recipient's Public Key" field.
|
58 |
+
- Generate and download the encrypted PNG image.
|
59 |
|
60 |
+
### Step 2: Send the Image to the API
|
61 |
|
62 |
+
Make a #`POST` request to the API endpoint with the encrypted image.
|
63 |
+
|
64 |
+
- **Endpoint URL**: #`https://broadfield-dev-keylock-rsa-js.hf.space/api/decode`
|
65 |
+
- **Method**: #`POST`
|
66 |
+
- **Body Type**: #`multipart/form-data`
|
67 |
+
- **Field Name**: The image file must be sent in a field named #`authImage`.
|
68 |
|
69 |
---
|
70 |
|
71 |
+
## API Response Format
|
72 |
+
|
73 |
+
#### On Success (Status 200 OK)
|
74 |
+
|
75 |
+
The API will return a JSON object containing the decrypted data.
|
76 |
+
|
77 |
+
```json
|
78 |
+
{
|
79 |
+
"success": true,
|
80 |
+
"data": {
|
81 |
+
"YOUR_KEY_1": "your_decrypted_value_1",
|
82 |
+
"YOUR_KEY_2": "your_decrypted_value_2"
|
83 |
+
}
|
84 |
+
}
|
85 |
+
```
|
86 |
+
|
87 |
+
#### On Failure (Status 400 or 500)
|
88 |
+
|
89 |
+
The API will return a JSON object with a descriptive error message.
|
90 |
+
|
91 |
+
```json
|
92 |
+
{
|
93 |
+
"success": false,
|
94 |
+
"error": "Decryption failed: The image may be corrupt or was not encrypted with the correct public key."
|
95 |
+
}
|
96 |
+
```
|
97 |
+
|
98 |
+
---
|
99 |
+
|
100 |
+
## Example: Using `fetch` in JavaScript
|
101 |
+
|
102 |
+
Here is a simple example of how to call this API from a web application.
|
103 |
+
|
104 |
+
```javascript
|
105 |
+
async function decodeImageWithApi(imageFile) {
|
106 |
+
const apiUrl = 'https://broadfield-dev-keylock-rsa-js.hf.space/api/decode';
|
107 |
+
|
108 |
+
// Create a FormData object to send the file
|
109 |
+
const formData = new FormData();
|
110 |
+
formData.append('authImage', imageFile);
|
111 |
+
|
112 |
+
try {
|
113 |
+
const response = await fetch(apiUrl, {
|
114 |
+
method: 'POST',
|
115 |
+
body: formData,
|
116 |
+
});
|
117 |
+
|
118 |
+
const result = await response.json();
|
119 |
+
|
120 |
+
if (!response.ok) {
|
121 |
+
throw new Error(result.error || `Server responded with status ${response.status}`);
|
122 |
+
}
|
123 |
+
|
124 |
+
console.log('Successfully Decoded Data:', result.data);
|
125 |
+
return result.data;
|
126 |
+
|
127 |
+
} catch (error) {
|
128 |
+
console.error('API call failed:', error.message);
|
129 |
+
// Handle the error in your UI
|
130 |
+
}
|
131 |
+
}
|
132 |
|
133 |
+
// How to use it:
|
134 |
+
// const myImageFile = document.getElementById('my-file-input').files[0];
|
135 |
+
// if (myImageFile) {
|
136 |
+
// decodeImageWithApi(myImageFile);
|
137 |
+
// }
|
138 |
+
```
|
139 |
|
140 |
+
You can test this API live using the **[Official Test Client](https://broadfield-dev-keylock-js-test.static.hf.space/)**.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|