Skip to content

🔑 Simple API for enrypting/decrypting text messages

License

Notifications You must be signed in to change notification settings

cheatsnake/classify

Repository files navigation

🔑 Classify

GitHub repo size GitHub contributions welcome

Telegram bot now available

Classify is open source project for enrypting text messages. Encryption is based on a simple and clear "One-time pad" method. The essence of this method is to apply the "exclusive OR" operation for each ASCII code of the message symbol in binary form and the corresponding ASCII code of the secret key.

👓 API overview

Classify API provides unlimited access to encoding and decoding text messages using a given key. You can freely use the endpoints of this API to create your own apps.

🔒 Encrypting data

This endpoint accepts text message data and a secret key as input. At the output, the user receives a JSON object with an encoded message.

POST /api/encrypt
{
    "data": "Your message",
    "key": "Your key"
}

🔓 Decrypting data

This endpoint accepts an encrypted text message and a secret key as input. At the output, the user receives a JSON object with a decrypted message.

POST /api/decrypt
{
    "data": "Encrypted message",
    "key": "Secret key"
}

🔑 Keygen

The reliability of the encrypted message depends on the specified key. Ideally, the key should be randomly generated and have a message length. To do this, you can use our built-in key generator.

GET /api/keygen

Key length parameter:

?length=32

Presence of symbols (1 - true, 0 - false):

?symbols=1

🎯 Examples

JavaScript:

const encryptData = async () => {
    try {
        const url = 'http://localhost:5000/api/encrypt';
        const jsonData = JSON.stringify({
            data: "Hello world!", key: "secret"
        });
        let response = await fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json;charset=utf-8'
            },
            body: jsonData
        });
        const result = await response.json();
        console.log(result);
    } catch (error) {
        console.error(error);
    }
}

⚡ Launch local server

  1. Install packages
npm install
  1. Create .env file with secret key
SECRET_KEY=CreateReliableKeyUsingRandomGenerator

⚠️ ⚠️ ⚠️ Classify uses double encryption. This means that after encrypting the message with your key, the received encrypted message is encrypted again with the key that is defined in the .env file. Therefore, each created copy of the application will have its own built-in key, and will not support decryption of encrypted messages from another copies of application.

  1. Runs the server with Nodemon for development
npm run dev

The page will reload if you make edits.
You will also see any lint errors in the console.
Open http://localhost:5000 to view it in the browser.

  1. Launch tests
npm run test
  1. Create a production build
npm run build
  1. Runs the server of production build
npm start

Open http://localhost:5000 to view it in the browser.

🐳 Docker startup

  1. Change ENV SECRET_KEY in Dockerfile.

  2. Build docker image from Dockerfile:

docker build . -t classify
  1. Create docker container from new image:
docker run -p 5000:5000 -d --name classify-server classify