asymmetric-key - Linux


Overview

asymmetric-key manages asymmetric key pairs for use in cryptographic operations. It allows users to create, import, export, and list key pairs, and to perform operations such as signing, verification, encryption, and decryption. Asymmetric cryptography is essential for ensuring secure communication and data protection.

Syntax

asymmetric-key [command] [options] [args]

Options

  • -c, –create Create a new key pair with the specified algorithm and length.
    • -a, –algorithm Specify the encryption algorithm to use (default: RSA).
    • -l, –length Specify the key length in bits (default: 4096).
  • -i, –import Import a key pair from a file or a certificate.
    • -f, –file Specify the file containing the key pair.
    • -c, –certificate Specify a certificate containing the public key.
  • -e, –export Export a key pair to a file.
    • -o, –out Specify the file where to save the key pair.
    • -p, –password Encrypt the private key with a password.
  • -l, –list List all available key pairs.
  • -s, –sign Sign a message using a private key.
    • -m, –message Specify the message to sign.
    • -o, –output Specify the file where to save the signature.
  • -v, –verify Verify a signature using a public key.
    • -m, –message Specify the message to verify.
    • -s, –signature Specify the signature to use.
  • -E, –encrypt Encrypt a message using a public key.
    • -m, –message Specify the message to encrypt.
    • -o, –output Specify the file where to save the ciphertext.
  • -D, –decrypt Decrypt a message using a private key.
    • -m, –message Specify the message to decrypt.
    • -o, –output Specify the file where to save the plaintext.
  • -h, –help Display help information

Examples

Create a new RSA key pair:

asymmetric-key -c -a RSA -l 4096

Import a key pair from a file:

asymmetric-key -i -f key_pair.pem

List all available key pairs:

asymmetric-key -l

Sign a message using a private key:

asymmetric-key -s -m "Hello World" -o signature.txt

Verify a signature using a public key:

asymmetric-key -v -m "Hello World" -s signature.txt

Common Issues

  • Error importing a key pair: Make sure the file contains the correct key format and that the password is correct (if encrypted).
  • Error signing a message: Verify that the private key is valid and the message is not corrupted.
  • Error verifying a signature: Check that the public key matches the private key used to sign the message and that the signature is not forged.

Integration

Asymmetric-key can be integrated with other Linux commands for advanced tasks:

  • Generating a CSR (Certificate Signing Request):
openssl req -new -key asymmetric-key -out csr.pem
  • Creating a self-signed certificate:
openssl x509 -req -in csr.pem -days 365 -signkey asymmetric-key -out certificate.pem

Related Commands

  • openssl – a general-purpose cryptography tool
  • pkcs12 – a tool to manipulate PKCS#12 files
  • gpg – a tool to manage and use GNU Privacy Guard (GPG) keys