📜  openssl windows - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:03:23.140000             🧑  作者: Mango

OpenSSL Windows - Shell Bash

OpenSSL is a robust, open-source cryptographic toolkit that provides encryption, decryption, and certificate generation functionalities. In Windows, OpenSSL can be installed and used via the Shell Bash command-line interface.

Installing OpenSSL on Windows
  1. Firstly, download and install the Windows Subsystem for Linux (WSL) by following the instructions provided in the Microsoft Documentation: https://docs.microsoft.com/en-us/windows/wsl/install-win10.

  2. After the installation, open the Windows Terminal or any other terminal emulator that supports WSL.

  3. Run the following command to install OpenSSL:

    sudo apt-get update && sudo apt-get install openssl
    

    This will update the package manager and install OpenSSL.

Using OpenSSL on Windows Shell Bash

OpenSSL on Windows Shell Bash can be used for various cryptographic operations like generating private/public key pairs, encrypting/decrypting files, and creating digital certificates.

Generating private/public key pairs

To generate an RSA private key and save it to a file, run the following command:

openssl genrsa -out private-key.pem 2048

This command generates a 2048-bit RSA private key and saves it to a file named private-key.pem.

To generate the corresponding public key, run the following command:

openssl rsa -in private-key.pem -outform PEM -pubout -out public-key.pem

This command generates a PEM-encoded public key file named public-key.pem.

Encrypting/decrypting files

To encrypt a file using OpenSSL on Windows Shell Bash, run the following command:

openssl enc -aes-256-cbc -salt -in plaintext_file.txt -out encrypted_file.enc

This command encrypts the file plaintext_file.txt using the AES-256 CBC encryption algorithm and saves the encrypted output to the file encrypted_file.enc.

To decrypt the encrypted file, run the following command:

openssl enc -aes-256-cbc -d -in encrypted_file.enc -out decrypted_file.txt

This command decrypts the file encrypted_file.enc and saves the decrypted output to the file decrypted_file.txt.

Creating digital certificates

To create a digital certificate using OpenSSL on Windows Shell Bash, run the following command:

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

This command creates a self-signed X.509 digital certificate that is valid for 365 days. The private key is saved to the file private-key.pem, and the certificate is saved to the file certificate.pem.

Conclusion

OpenSSL on Windows Shell Bash provides a powerful toolset for various cryptographic operations. It can be used to generate key pairs, encrypt/decrypt files, and create digital certificates. OpenSSL is an essential tool for any developer working with cryptography and security-related applications.