Skip to content

Commit

Permalink
Lab-3 : Task 1, 2, 5, 6 completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakib62 committed May 7, 2024
1 parent 80380ca commit a0d5afa
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 1 deletion.
57 changes: 56 additions & 1 deletion Lab-3/Task-1/Readme.md
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
# Task - 1
# Task - 1 : AES encryption using different modes

The modes that will be used are : AES-128-CBC, AES-128-CFB, AES-128-ECB

The steps followed are :

1. Create a text file and add some texts.
2. `Encrypt` this file with `AES-128-CBC` using following command:

```
$ openssl enc -aes-128-cbc -e -in test.txt -out encrypt-aes-128-cbc.bin -k 00112233445566778889aabbccddeeff -iv 01020304050607080102030405060708
```
Encrypted File : [encrypt-aes-128-cbc.bin](encrypt-aes-128-cbc.bin)
3. `Decrypt` the encrypted file with `AES-128-CBC` using following command:
```
openssl enc -aes-128-cbc -d -in encrypt-aes-128-cbc.bin -out decrypt-aes-128-cbc.txt -k 00112233445566778889aabbccddeeff -iv 01020304050607080102030405060708
```
Decrypted File : [decrypt-aes-128-cbc.txt](decrypt-aes-128-cbc.txt)
Similarly, we will encrypt and decrypt the file using two other modes.
### AES-128-CFB
- Encryption
```
openssl enc -aes-128-cfb -e -in test.txt -out encrypt-aes-128-cfb.bin -k 00112233445566778889aabbccddeeff -iv 01020304050607080102030405060708
```
Encrypted File : [encrypt-aes-128-cfb.bin](encrypt-aes-128-cfb.bin)
- Decryption
```
openssl enc -aes-128-cfb -d -in encrypt-aes-128-cfb.bin -out decrypt-aes-128-cfb.txt -k 00112233445566778889aabbccddeeff -iv 01020304050607080102030405060708
```
Decrypted File : [decrypt-aes-128-cfb.txt](decrypt-aes-128-cfb.txt)
### AES-128-ECB
In ECB mode, no iv (initialisation vector is needed)
- Encryption
```
openssl enc -aes-128-ecb -e -in test.txt -out encrypt-aes-128-ecb.bin -k 00112233445566778889aabbccddeeff
```
Encrypted File : [encrypt-aes-128-ecb.bin](encrypt-aes-128-ecb.bin)
- Decryption
```
openssl enc -aes-128-ecb -d -in encrypt-aes-128-ecb.bin -out decrypt-aes-128-ecb.txt -k 00112233445566778889aabbccddeeff
```
Decrypted File : [decrypt-aes-128-ecb.txt](decrypt-aes-128-ecb.txt)
3 changes: 3 additions & 0 deletions Lab-3/Task-1/decrypt-aes-128-cbc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Information and Network Security course lab assignment - using openssl, hex editor and various encryption algorithm.

Goal is to perform various encryption and decryption task and compare among different algorithm.
3 changes: 3 additions & 0 deletions Lab-3/Task-1/decrypt-aes-128-cfb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Information and Network Security course lab assignment - using openssl, hex editor and various encryption algorithm.

Goal is to perform various encryption and decryption task and compare among different algorithm.
3 changes: 3 additions & 0 deletions Lab-3/Task-1/decrypt-aes-128-ecb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Information and Network Security course lab assignment - using openssl, hex editor and various encryption algorithm.

Goal is to perform various encryption and decryption task and compare among different algorithm.
3 changes: 3 additions & 0 deletions Lab-3/Task-1/encrypt-aes-128-cbc.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Salted__X5�9W@U�oY�+/
�Hu�N��G!�˙�~�\?XP4p�.���v6ͣ1m4��R� s� aw~�AD�ᥟ�EB�Sv��*��yF�k��������G�~�k5�Z�d�r�<�S�~S�Ԯ[��$������?� �
�^��� mb{H5���f_�.��E��R��5�<�EΝK�Ӆ�jиVW��R��e�4>�glD�(MZ���e������C�k
Expand Down
Binary file added Lab-3/Task-1/encrypt-aes-128-cfb.bin
Binary file not shown.
1 change: 1 addition & 0 deletions Lab-3/Task-1/encrypt-aes-128-ecb.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Salted__1◙,������{�kbz0��ز�d���e^�{���$A.m̢�$W�)䘎��Wk���TR��&.�c()Xg� �� �[\i=��o� M7�� �O҂���B`yhZZ�]�S&\pG g"��݂p��'��`��-דCt�:-S�����W�T-O�q��H�Zb���:Q�Rru�.���0�y@{���?�Z�7�V��q����B�R��A�iL�-���G�>
Expand Down
3 changes: 3 additions & 0 deletions Lab-3/Task-1/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Information and Network Security course lab assignment - using openssl, hex editor and various encryption algorithm.

Goal is to perform various encryption and decryption task and compare among different algorithm.
46 changes: 46 additions & 0 deletions Lab-3/Task-2/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Task - 2 : Encryption mode - ECB vs CBC

### AES ECB

1. Download a .bmp file and name it. I named my file [penguin.bmp](penguin.bmp)
2. Encrypt the image with ECB mode, using following command:

```
openssl enc -aes-128-ecb -e -in penguin.bmp -out encryptedECB.bmp -K 00112233445566778889aabbccddeeff
```
3. For the .bmp file, the first 54 bytes contain the header information about the picture. But due to encryption, those 54 bytes changed. So, we have to replace the header of encrypted image with that of original image.
4. To do that, open the original image in `HEX Workshop`. Copy the first 54 bytes.
5. Now Open the encrypted image in `HEX Workshop`. Replace the first 54 bytes with the original image's header information.
6. Now open the [encryptedECB.bmp](encryptedECB.bmp) with a picture viewing software to display it. Here, the shape of penguin can be understood, but penguin is not visible completely.
### AES CBC
1. Encrypt the image with CBC mode using following command :
```
openssl enc -aes-128-cbc -e -in penguin.bmp -out encryptedCBC.bmp -K 00112233445566778889aabbccddeeff -iv 20304050607082143234324324233333
```
2. Open the original image with `HEX Workshop` and copy the first 54 bytes. These are header information.
3. Open the encrypted image with `HEX Workshop` and replace the first 54 bytes with the original header information.
4. Open the [encryptedCBC.bmp](encryptedCBC.bmp) in any picture viewing software to display it. The image is not recognizable and shape of the penguin cannot be understood.
### My Observation
1. **ECB mode (Electronic Codebook):**
- Each block of plaintext is encrypted independently with the same key.
- Identical blocks of plaintext results in identical blocks of ciphertext.
- Less secure for image encryption as patterns, shape may be recognized from encrypted file.
2. **CBC mode (Cipher Block Chaining):**
- Each block of plaintext is XORed with the previous ciphertext block before encryption.
- More resistant to patterns and repetition in the plaintext due to added diffusion.
- IV (Initialization Vector) is needed for the first block to start the chaining process. Hence, CBC is slower and more complex than ECB mode.
So, conclusion is `CBC is better than ECB for image encryption` as CBC is more resistant to pattern preservation and provides better security.
Binary file added Lab-3/Task-2/encryptedCBC.bmp
Binary file not shown.
Binary file added Lab-3/Task-2/encryptedECB.bmp
Binary file not shown.
Binary file added Lab-3/Task-2/penguin.bmp
Binary file not shown.
51 changes: 51 additions & 0 deletions Lab-3/Task-5/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Task - 5 : Generating Message Digest

Following steps are followed to generate hash value of a file:

1. Create a text file and add some text. I named it [text.txt](text.txt)
2. Use the `SHA-256` (Secure Hashing Algorithm) hashing algorithm by the following command:

```
openssl dgst -sha256 text.txt
```
Generated Hash:
```
2862d2fda986953340b9ad696afb168a6bd02eaa04efaea80452278f5852d416
```
3. Use the `SHA-1` hashing algorithm by the following command:
```
openssl dgst -sha1 text.txt
```
Generated Hash:
```
8f0e7d6587f3d754343ead29c2115174891a6c1e
```
4. Use the `MD-5` (Message Digest) hashing algorithm by the following command:
```
openssl dgst -md5 text.txt
```
Generated Hash:
```
4ef7690f6ba6af63db4de8e29da21bd9
```
### Observations
1. **SHA-256**
- Produces longer hash value (256bit, 32-byte) compared to MD5 and SHA-1.
- Provides better security against collisions and widely used in modern cryptographic application including digital signatures, certificate authorities, password hashing, and blockchain technology.
2. **SHA-1**
- Produces 160 bit (20 byte) hash value.
- Considered weak and vulnerable to collision attacks.
3. **MD5**
- Produces 128 bit (16 byte) hash value.
- Fast and commonly used for checksums and data integrity verification.
- Vulnerable to collision attacks.
So, `SHA-256 is the most secure one.` MD5, thought fast, considered insecure. SHA-1 is stronger than MD5 but also vulnerable to collision attacks and less secure than SHA-256.
1 change: 1 addition & 0 deletions Lab-3/Task-5/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is for checking one way hash algorithm such as md5, sha1, sha256. So, I opened a text file and generated hash for each algorithm and the commands to do that.
37 changes: 37 additions & 0 deletions Lab-3/Task-6/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Task - 6 : Keyed hash and HMAC

The following steps are followed to generate Keyed Hash and HMAC:

1. Create a text file and add some text. I named it [text.txt](text.txt)
2. Generate a keyed hash using `HMAC-MD5` algorithm by the following command
```
openssl dgst -md5 -hmac "key for hash based mac" text.txt
```
Generated Hash:
```
0eecf7180df087de9b3c42cbc0961243
```
3. Generate a keyed hash using `HMAC-SHA1` algorithm by the following command
```
openssl dgst -sha1 -hmac "key for hash based mac" text.txt
```
Generated Hash:
```
9935d4ad0a05a67b6bf1e2f57e936a6a00703a72
```
4. Generate a keyed hash using `HMAC-SHA256` algorithm by the following command
```
openssl dgst -sha256 -hmac "key for hash based mac" text.txt
```
Generated Hash:
```
85805be3217d735e2c998bca83457f208aa19eb7866b17f4da4bd97eab29ab38
```
### Key size in HMAC
- HMAC does not require a key with a fixed size. It can accept keys of any length.
- The key size should be chosen based on the security requirements of the application and the cryptographic algorithm being used.
- However, for HMAC, it's `recommended to use keys that are at least as long as the block size` of the underlying hash function. Such as 16 bytes for HMAC-MD5, 20 bytes for HMAC-SHA1, 32 bytes for HMAC-SHA256.
- If the provided key is shorter than the block size of the hash function, it is usually padded to match the block size using appropriate padding schemes
- Using longer keys can provide better security against brute-force attacks, but excessively long keys may not necessarily enhance security significantly and can incur additional overhead in terms of processing and storage.
1 change: 1 addition & 0 deletions Lab-3/Task-6/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In this file, we are trying to generate a keyed hash for a file. In cryptography, an HMAC is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. So, after creating a file with some text in it, we are using HMAC-MD5, HMAC-SHA256, HMAC-SHA1 to generate a keyed hash for each algorithm.
1 change: 1 addition & 0 deletions Lab-3/Task-7/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Task - 7 :

0 comments on commit a0d5afa

Please sign in to comment.