Monday, November 4, 2024

Cybersecurity Essential: OpenSSL

In today’s digital landscape, securing data is paramount. Whether you’re building web applications, managing servers, or developing software that handles sensitive information, understanding cryptography is essential. OpenSSL is a powerful toolkit that software engineers can leverage for a variety of cryptographic functions. In this blog, we’ll explore what OpenSSL is, its core functionalities, and how you can effectively use it in your projects.

What is OpenSSL?

OpenSSL is an open-source implementation of the SSL and TLS protocols. It provides libraries for secure communication and a suite of command-line tools for performing various cryptographic operations, such as encryption, decryption, certificate management, and generating keys. Its versatility makes it a staple for software engineers and system administrators alike.

Core Features of OpenSSL

  1. Encryption and Decryption: OpenSSL allows you to encrypt and decrypt files and data using various algorithms, including AES, DES, and RSA.
  2. Certificate Management: It helps in creating, signing, and managing SSL/TLS certificates, which are crucial for secure web communications.
  3. Hashing: OpenSSL provides functions for generating cryptographic hashes using algorithms like SHA-256 and MD5, which are essential for data integrity checks.
  4. Key Generation: You can generate secure keys for symmetric and asymmetric encryption, ensuring that your cryptographic operations are based on strong keys.
  5. Support for Protocols: OpenSSL supports various secure protocols such as HTTPS, FTPS, and more, allowing for secure data transmission.

Getting Started with OpenSSL

Installation

OpenSSL is available on most operating systems. You can install it via package managers or build it from source. 

  • On macOS:

brew install openssl

  • On Ubuntu:

sudo apt-get install openssl

  • On Windows: You can download a precompiled binary or build it from source using tools like Cygwin or MinGW. OpenSSL is usually installed with Git, inside Git install directory under /usr/bin folder.

Basic Commands

Here are some common OpenSSL commands that software engineers will find useful:

1. Encrypting and Decrypting Files

To encrypt a file using AES-256-CBC:

    
    openssl enc -aes-256-cbc -salt -in plaintext.txt -out encrypted.bin

To decrypt the file:


    openssl enc -d -aes-256-cbc -in encrypted.bin -out decrypted.txt -k yourpassword

2. Generating RSA Keys

Generate a private key:


    openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048

Extract the public key from the private key:


    openssl rsa -pubout -in private_key.pem -out public_key.pem

3. Creating a Self-Signed Certificate

To create a self-signed SSL certificate:


    openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem

This command generates both a private key and a self-signed certificate valid for 365 days.

4. Hashing Data

To create a SHA-256 hash of a file:


    openssl dgst -sha256 yourfile.txt

Integrating OpenSSL in Software Projects

OpenSSL can be integrated into software projects in various ways, including:

  • Secure Socket Layer: Use OpenSSL libraries to establish secure connections in applications.
  • Data Encryption: Implement file encryption and decryption in your applications to protect sensitive data.
  • SSL/TLS Certificates: Manage certificates programmatically for web servers or APIs.
  • API Security: Use OpenSSL for signing and verifying JSON Web Tokens (JWT) or other authentication tokens.

Conclusion

OpenSSL is an invaluable tool for software engineers, providing the means to implement secure communications and protect sensitive data. By mastering its command-line tools and libraries, you can enhance the security of your applications and build trust with your users. Whether you’re encrypting files, managing certificates, or establishing secure connections, OpenSSL equips you with the essential capabilities to navigate the complex world of cryptography confidently.

Content inspired using ChatGPT.


Tuesday, May 21, 2024

Top AI Tools

Download and Install Python


Download and Install Pycharm


Install Jupyter

> pip install jupyter


Install Transformers

> pip install transformers

> pip install transformers[sentencepiece]


Install Pytorch (Preferred for dev)/TensorFlow (preferred for prod)

> pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118


Friday, May 17, 2024

MongoDb CheatSheet

CRUD Operations:

Create

db.products.insert({item:"TV",aqty:200,soldqty:1200,avail:true})

db.createCollection("Name")


Read:

db.products.find({<Condition>},{<Projection>})

Get single document - db.products.findOne()

Get all documents - db.products.find()

Get documents based on filters - db.products.find({aqty:0})

Get documents with particular fields - db.products.find({aqty:0},{item:1,soldqty:1})

Reading the data with limit(), sort(), skip() functions:

db.products.find().sort({aqty:1}).limit(5)

db.products.find().sort({aqty:1}).skip(5)


Operators: in, ne, nin, lt, gt, lte, gte, or, and

IN -  db.products.find({aqty:{$in:[0,200]}})

Less Than & And - db.products.find({aqty:{$lt:200},soldqty:1800})

OR - db.products.find({$or:[{aqty:200},{soldqty:3000}]}) 

        db.products.find({$or:[{aqty:{$lt:200}},{soldqty:{$gt:1800}}]})


Update:

add/update property - db.products.updateMany({},{$set:{price:100}})

remove property - db.products.updateMany({}, {$unset: {price: 0}})


Delete:

collection - db.test.drop()

single row - db.products.deleteOne({item:'TV'})

multiple row - db.products.deleteMany({prices:{$lt: 200}})

all rows - db.products.deleteMany({})


Indexes:

db.products.createIndex({price:1})


Aggregation:


https://www.mongodb.com/developer/products/mongodb/cheat-sheet/


Tuesday, May 14, 2024

Deep Dive in Asynchronous Programming in Javascript

JavaScript is single threaded language. 

Synchronous programming is execution of functions in order.

Asynchronous programming is executing a long running process outside the main thread. It does not block code execution on main thread. Although it is achieved usually by running asynchronous function on separate thread. Though javascript is a single threaded language it supports aysnchronous behaviour, to understand how we need to understand JS runtime.

 




Cybersecurity Essential: OpenSSL

In today’s digital landscape, securing data is paramount. Whether you’re building web applications, managing servers, or developing software...