- This project is used as a template for the encryption applications in a WEB API.
- The server will be performing encrypt/decrypt methods for some kind of text messages.
- asymmetric_encryption
- symmetric_encryption
- about asymmetric encryption
- node_documentation
- mysql_CLI_documentation
- mocha_testing_documentation
- assert_documentation
- Clone the project in your machine.
git clone https://github.com/AlfonsoG-dev/EncryptionSamples- Install node dependencies.
npm i- Configure database by creating the connection file and class using the following example.
import mysql2 from "mysql2"
import { configDotenv } from "dotenv"
configDotenv()
export default class DBConfig {
db_name
constructor() {
this.db_name = "database_name"
}
get config() {
return {
host: "localhost",
port: "3306",
user: "",
password: process.env.DB_PASSWORD,
database: this.db_name
}
}
get cursor() {
return mysql2.createConnection(this.config)
}
}for the database you will find a script to build the tables in the SQL folder.
- you only need to source it in the mysql server CLI.
cd ./sql/
mysql -u root -p
mysql > source script.sql;- Create the environment variables.
NODE_ENV='development' -- if you want to test locally otherwise use **production**
DB_PASSWORD=#database password
API_PORT='3000' --port for the server
API_HOST='127.0.0.1' -- IP also you can use **localhost**
PASSPHRASE=#secure phrase for secret key generation
SECRET_KEY=#use the encrypt methods to generate
IV=#use the encrypt methods to generate- Create a user for the API.
- Run the API.
npm start- Make HTTP requests to the API end-points.
the server is running in the port: 3000
- Create the first user for testing and message for testing
POST http://localhost:3000/user/post-user
Content-Type: application/json
{
"email": "test@gmail.com",
"alias": "test",
"password": "123asd"
}
POST http://localhost:3000/message/post-message
Content-Type: application/json
{
"user_id_fk": 1,
"head": "test message",
"body": "this is a test message"
}- Execute test.
npm run test- This project its for educational purposes.
- Security issues are not taken into account.
- Use at your own risk.