Spaces:
Sleeping
Sleeping
title: KeyLock RSA JS | |
emoji: π | |
colorFrom: indigo | |
colorTo: yellow | |
sdk: docker | |
pinned: false | |
# Secure KeyLock Decoder API | |
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. | |
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. | |
## Live API Status | |
You can check if the API is running by visiting the root of its direct URL: | |
- **Health Check:** **[https://broadfield-dev-keylock-rsa-js.hf.space/](https://broadfield-dev-keylock-rsa-js.hf.space/)** | |
If the server is running correctly, you will see a JSON response like #`{"status":"ok",...}`. | |
--- | |
## How to Use This API | |
The process involves two main steps: encrypting the data into an image, and then sending that image to this API for decryption. | |
### Step 1: Encrypt Your Data | |
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. | |
**Service Public Key:** | |
```pem | |
-----BEGIN PUBLIC KEY----- | |
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3U12blsrWcopidojVmzZ | |
cdbk+OwRAbU1dJyrlccSQyejXSCeBZjexVO129UyBP+u+/TsQSp7t2s3DoRaSq6s | |
X8mxMVcwYKB/6UPmEiwBIRGudDgMzHHEVzYm8fznJSwZr+kj4ox+rk2xopB64wIb | |
EqGaY/GC1JXm+8dRUh8h/5ZOxftRXmIF2xwPjTEV7jMOGIhCgPQ0Jf+yuAfGmj1/ | |
1L9su5JW+UzgCbiYkDWccUqna4yBpdjybgXs7ZhbRQMjqyakS/qnXlLSh/FvD/Oi | |
xb9UiBpRJS3jmTMnqbYU19PigVkm7kpY0zubpiyp2p8UL7OODqxnWCetjQ6b3tyL | |
UwIDAQAB | |
-----END PUBLIC KEY----- | |
``` | |
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). | |
- On the "Embed Data" tab, enter your secret data (e.g., #`USERNAME: myuser`). | |
- Paste the **Service Public Key** from above into the "Recipient's Public Key" field. | |
- Generate and download the encrypted PNG image. | |
### Step 2: Send the Image to the API | |
Make a #`POST` request to the API endpoint with the encrypted image. | |
- **Endpoint URL**: #`https://broadfield-dev-keylock-rsa-js.hf.space/api/decode` | |
- **Method**: #`POST` | |
- **Body Type**: #`multipart/form-data` | |
- **Field Name**: The image file must be sent in a field named #`authImage`. | |
--- | |
## API Response Format | |
#### On Success (Status 200 OK) | |
The API will return a JSON object containing the decrypted data. | |
```json | |
{ | |
"success": true, | |
"data": { | |
"YOUR_KEY_1": "your_decrypted_value_1", | |
"YOUR_KEY_2": "your_decrypted_value_2" | |
} | |
} | |
``` | |
#### On Failure (Status 400 or 500) | |
The API will return a JSON object with a descriptive error message. | |
```json | |
{ | |
"success": false, | |
"error": "Decryption failed: The image may be corrupt or was not encrypted with the correct public key." | |
} | |
``` | |
--- | |
## Example: Using `fetch` in JavaScript | |
Here is a simple example of how to call this API from a web application. | |
```javascript | |
async function decodeImageWithApi(imageFile) { | |
const apiUrl = 'https://broadfield-dev-keylock-rsa-js.hf.space/api/decode'; | |
// Create a FormData object to send the file | |
const formData = new FormData(); | |
formData.append('authImage', imageFile); | |
try { | |
const response = await fetch(apiUrl, { | |
method: 'POST', | |
body: formData, | |
}); | |
const result = await response.json(); | |
if (!response.ok) { | |
throw new Error(result.error || `Server responded with status ${response.status}`); | |
} | |
console.log('Successfully Decoded Data:', result.data); | |
return result.data; | |
} catch (error) { | |
console.error('API call failed:', error.message); | |
// Handle the error in your UI | |
} | |
} | |
// How to use it: | |
// const myImageFile = document.getElementById('my-file-input').files[0]; | |
// if (myImageFile) { | |
// decodeImageWithApi(myImageFile); | |
// } | |
``` | |
You can test this API live using the **[Official Test Client](https://broadfield-dev-keylock-js-test.static.hf.space/)**. |