Spaces:
Sleeping
Sleeping
File size: 4,193 Bytes
8588447 122c74c 8588447 54b5dfd 3b8deb4 07a0aaa 3b8deb4 54b5dfd 3b8deb4 54b5dfd 3b8deb4 54b5dfd 3b8deb4 54b5dfd 3b8deb4 54b5dfd 3b8deb4 |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
---
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/)**. |