Skip to content

uttam-bc/safecode-files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Name : SafeCode Files

Description :

SafeCode Files is a project designed to store user information securely by encrypting the data using public-key cryptography. Instead of storing sensitive information in plain text, the data is encoded with a public key and saved in an encrypted format. When the user needs to access the information, the software reads the encrypted file and decodes it using the corresponding private key. Key Features: Public-Key Encryption: Each user is assigned a unique set of public and private keys. Secure Storage: Information is stored in an encrypted format to ensure privacy and security. Decryption on Demand: Data can only be decoded by the user who possesses the correct private key. How It Works: The user inputs their information into the software. The software encrypts the information using the user's public key. The encrypted data is stored in a secure file. When the user needs to retrieve the information, they use their private key to decrypt the data through the software. Prerequisites: Knowledge of public-key cryptography. Tools or libraries for encryption and decryption (e.g., RSA). Use Cases: Personal Data Protection: Safeguard personal information like passwords, financial records, or private notes. Corporate Security: Store confidential business information securely. Compliance: Meet data protection standards by ensuring sensitive data is encrypted. This code is a simple Flask web application that implements user registration, login, encryption, decryption, and file upload functionalities. It uses SQLite as the database and RSA encryption for message security. Below is a breakdown of the key parts of the code:

  1. Imports Flask: A web framework for building web applications. cryptography: A library to handle cryptographic operations, specifically RSA encryption and decryption. sqlite3: A lightweight, serverless database engine used to store user data and encrypted messages. os: Provides functions to interact with the operating system (though not used in this code).
  2. App Initialization app = Flask(name): Initializes the Flask web application. app.secret_key: This is used to sign session cookies and secure session data (important for user login/logout).
  3. Database Setup (init_db) Initializes two tables in the SQLite database: users: Stores user data like username, password, and RSA keys (private_key, public_key). messages: Stores encrypted messages along with a reference to the user who created the message. The CREATE TABLE IF NOT EXISTS statement ensures that the tables are only created once.
  4. Key Generation (generate_keys) This function generates a new RSA key pair (private and public keys) for encryption and decryption. rsa.generate_private_key(): Generates a private key. public_key = private_key.public_key(): Derives the public key from the private key. The keys are serialized to PEM format, which is a standard format for encoding cryptographic data. The keys are returned as strings.
  5. Routes / (Home) If a user is logged in ('username' in session), it renders a home.html template with the user's name. Otherwise, it redirects the user to the login page. /register (User Registration) Displays a registration form where users can provide their username and password. When the form is submitted, the server generates RSA keys, stores the username, password, and keys in the users table, and redirects to the login page. If the username already exists, it returns an error message. /login (User Login) Displays a login form where users can input their username and password. On form submission, it checks the credentials against the users table in the database. If valid, it stores the username, user ID, and keys in the session and redirects to the home page. If invalid, it returns an error message. /logout (User Logout) Clears the session and redirects to the login page. /encrypt (Message Encryption) Users can encrypt a message by providing it through a form. The message is encrypted using the logged-in user's public key using RSA and OAEP padding (a secure padding scheme). The encrypted message is then stored in the messages table, associated with the user's ID. /decrypt (Message Decryption) Fetches all encrypted messages from the messages table associated with the logged-in user. Each message is decrypted using the user's private key and displayed on the page. This provides a way for users to view the decrypted content of their messages. /upload (File Upload) Allows users to upload a file. The file's contents are read as a string (assuming it's a text file) and displayed. The form accepts a file, and once the file is uploaded, its contents are shown in a new page.
  6. Session Management The session is used to store user-specific information like their username, user_id, private_key, and public_key. The session persists across requests, so users remain logged in until they log out.
  7. Running the Application app.run(debug=True): Starts the Flask application in debug mode, meaning any changes in the code will automatically reload the server and errors will be displayed in the browser. Summary The application:

Allows users to register and log in. Generates and stores RSA keys for each user. Encrypts messages using a user’s public key and stores them in the database. Decrypts messages using the user’s private key. Allows users to upload and view text files. This application demonstrates the use of cryptography in securing messages and managing user sessions in a Flask-based web application.

About

cryptographic encryption of data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published