Home > AI > Uncategorized

openssl – encrypt and decrypt files by public and private keys

Some of the abbreviations related to certificates.

  • SSL – Secure Socket Layer
  • CSR – Certificate Signing Request
  • TLS – Transport Layer Security
  • PEM – Privacy Enhanced Mail
  • DER – Distinguished Encoding Rules
  • SHA – Secure Hash Algorithm
  • PKCS – Public-Key Cryptography Standards

RSA

Usage: it is usually used to encrypt password or file having password because if creating a key with n bits, then the file size should not exceed n-11 bits.

openssl genrsa: Generates an RSA private keys.

# private key doesn't have password
openssl genrsa -out private.key 2048 

# private key has password
openssl genrsa -aes256 -out private.key 1024 

openssl rsa: Manage RSA private keys (includes generating a public key from it).

# check private key content
# if there is a password to protect the key, it will be prompted
openssl rsa -check -in private.key


# remove password for the private key
# backup original private key or use a different name since failure operation will damage the original key
openssl rsa -in private.key -out private_no_pass.key


# make the private key password protected
# backup original private key or use a different name since failure operation will damage the original key
openssl rsa -aes256 -in private.key -out private_with_pass.key


# get public key from the private key
openssl rsa -in private.key -pubout -out pub.key

openssl rsautl: Encrypt and decrypt files with RSA keys.

# encryp file by the public key
openssl rsautl -encrypt -inkey pub.key -pubin -in data.txt -out data-e.txt

# decrypt file by the private key
openssl rsautl -decrypt -inkey private.key -in data.txt -out data-o.txt

Related posts:
Relevant tags:

Leave a Reply