Tag: symmetric

  • Advanced Encryption Standard

    Advanced Encryption Standard (AES)

    A symmetric block cipher selected by the U.S. National Institute of Standards and Technology (NIST) in 2001 to replace the older Data Encryption Standard (DES). AES is widely used to protect sensitive and classified information in both government and commercial applications.AES encrypts data in fixed-size blocks of 128 bits and supports key lengths of 128, 192, or 256 bits, providing strong security against modern cryptographic attacks. It operates using a series of substitution, permutation, and mixing operations across multiple rounds, depending on the key size (10 rounds for 128-bit keys, 12 rounds for 192-bit keys, and 14 rounds for 256-bit keys).

    echo “test” > input.txt # Create a file named input.txt containing the text “test”

    echo "test" > input.txt

    openssl # OpenSSL command-line cryptography tool
    enc # encryption/decryption utility
    -e # encrypt mode
    -aes-256-cbc # AES algorithm with 256-bit key in CBC mode
    -in input.txt # plaintext input file
    -out encrypted.txt # output encrypted file
    -k test # password used to derive the encryption key
    -iv 0 # initialization vector (IV) set to all zeros (INSECURE)

    openssl enc -e -aes-256-cbc -in input.txt -out encrypted.txt -k test -iv 0

    openssl # OpenSSL command-line cryptography tool
    -d # decrypt mode
    -aes-256-cbc # same algorithm and mode used for encryption
    -in encrypted.txt # input ciphertext file
    -out decrypted.txt # output decrypted file
    -k test # same password used to derive the key
    -iv 0 # same IV must be used for decryption

    openssl enc -d -aes-256-cbc -in encrypted.txt -out decrypted.txt -k test -iv 0

    cat decrypted.txt # Display the decrypted file contents

    cat decrypted.txt

    One liner

    echo test123 | openssl enc -k 33 -aes-256-ctr -nosalt -a | openssl enc -d -k 33 -aes-256-ctr -nosalt -a
  • Rivest Cipher 4

    Rivest Cipher 4 (RC4)

    A stream cipher designed by Ronald Rivest in 1987. Unlike block ciphers, which encrypt fixed-size blocks of data, RC4 encrypts data one byte at a time. This makes it well-suited for applications where data arrives in variable-length streams, such as network communications.RC4 generates a pseudorandom key stream based on an initial secret key. Each byte of plaintext is then combined with the key stream using the XOR operation to produce ciphertext. Decryption uses the same key to regenerate the key stream, and XOR is applied again to recover the original plaintext.

    echo “test” > input.txt # Create a file named input.txt containing the text “test”

    echo "test" > input.txt

    openssl # an open-source cryptography toolkit
    -e #encrypt
    -rc4 # RC4 algorithm (deprecated / insecure)
    -in input.txt # input plaintext file
    -out encrypted.txt # output encrypted file
    -K ‘000102030405060708090A0B0C0D0E0F’ # raw encryption key in hexadecimal (128-bit key)
    -provider legacy # required because DES is deprecated in OpenSSL 3+

    openssl enc -e -rc4 -in input.txt -out encrypted.txt -K '000102030405060708090A0B0C0D0E0F' -provider legacy

    openssl # an open-source cryptography toolkit
    -d # decrypt
    -rc4 # same algorithm and mode used for encryption
    -in encrypted.txt # input ciphertext file
    -out decrypted.txt # output decrypted file
    -K ‘000102030405060708090A0B0C0D0E0F’ # raw encryption key in hexadecimal (128-bit key)
    -nosalt # disables salt (needed because encryption used raw key)
    -provider legacy # enables deprecated DES support

    openssl enc -d -rc4 -in encrypted.txt -out decrypted.txt -K '000102030405060708090A0B0C0D0E0F' -nosalt -provider legacy

    cat decrypted.txt # Display the decrypted file contents

    cat decrypted.txt
  • Data Encryption Standard

    Data Encryption Standard (DES) 

    A symmetric key block cipher that was widely used for securing electronic data. DES operates by encrypting 64-bit blocks of data using a 56-bit key, producing a corresponding 64-bit ciphertext block.DES follows the Feistel structure, which means it divides the data block into two halves and applies multiple rounds of substitution and permutation to increase security. Each round uses the key in a complex transformation process to scramble the data, making it difficult for unauthorized parties to recover the original plaintext without the correct key.

    echo “test” > input.txt # Create a file named input.txt containing the text “test”

    echo "test" > input.txt

    openssl # an open-source cryptography toolkit
    -e #encrypt
    -des-ecb # use DES algorithm in ECB mode
    -in input.txt #input plaintext file
    -out encrypted.txt # output encrypted file
    -K 0001020304050607 # explicit 64-bit DES key in hex
    -provider legacy # required because DES is deprecated in OpenSSL 3+

    openssl enc -e -des-ecb -in input.txt -out encrypted.txt -K 0001020304050607 -provider legacy

    openssl # an open-source cryptography toolkit
    -d # decrypt
    -des-ecb # same algorithm and mode used for encryption
    -in encrypted.txt # input ciphertext file
    -out decrypted.txt # output decrypted file
    -K 0001020304050607 # same key used for encryption
    -nosalt # disables salt (needed because encryption used raw key)
    -provider legacy # enables deprecated DES support

    openssl enc -d -des-ecb -in encrypted.txt -out decrypted.txt -K '0001020304050607' -nosalt -provider legacy

    cat decrypted.txt # Display the decrypted file contents

    cat decrypted.txt