Cyber Unit 2 Notes
Cyber Unit 2 Notes
Cyber Unit 2 Notes
Encryption
The process of changing the plaintext into the ciphertext is referred to as encryption.
The encryption process consists of an algorithm and a key. The key is a value independent of the
plaintext.
The security of conventional encryption depends on the major two factors
1. The Encryption algorithm
2. Secrecy of the key
Once the ciphertext is produced, it may be transmitted. The Encryption algorithm will produce a
different output depending on the specific key being used at the time. Changing the key changes the
output of the algorithm.
Once the ciphertext is produced, it may be transmitted. Upon reception, the ciphertext can be
transformed back to the original plaintext by using a decryption algorithm and the same key that was
used for encryption.
Decryption
The process of changing the ciphertext to the plaintext that process is known as decryption.
Public Key Encryption: Asymmetric is a form of Cryptosystem in which encryption and decryption
are performed using different keys-Public key (known to everyone) and Private key (Secret key). This
is known as Public Key Encryption.
• Public key Encryption is important because it is infeasible to determine the decryption key
given only the knowledge of the cryptographic algorithm and encryption key.
• Either of the two keys (Public and Private key) can be used for encryption with another key
used for decryption.
• Due to Public key cryptosystem, public keys can be freely shared, allowing users an easy and
convenient method for encrypting content and verifying digital signatures, and private keys can
be kept secret, ensuring only the owners of the private keys can decrypt content and create
digital signatures.
• The most widely used public-key cryptosystem is RSA (Rivest–Shamir–Adleman). The
difficulty of finding the prime factors of a composite number is the backbone of RSA.
Components of Public Key Encryption
• Plain Text: This is the message which is readable or understandable. This message is given to
the Encryption algorithm as an input.
• Cipher Text: The cipher text is produced as an output of Encryption algorithm. We cannot
simply understand this message.
• Encryption Algorithm: The encryption algorithm is used to convert plain text into cipher text.
• Decryption Algorithm: It accepts the cipher text as input and the matching key (Private Key or
Public key) and produces the original plain text
• Public and Private Key: One key either Private key (Secret key) or Public Key (known to
everyone) is used for encryption and other is used for decryption
• Security: RSA algorithm is considered to be very secure and is widely used for secure data
transmission.
• Public-key cryptography: RSA algorithm is a public-key cryptography algorithm, which means
that it uses two different keys for encryption and decryption. The public key is used to encrypt
the data, while the private key is used to decrypt the data.
• Key exchange: RSA algorithm can be used for secure key exchange, which means that two
parties can exchange a secret key without actually sending the key over the network.
• Digital signatures: RSA algorithm can be used for digital signatures, which means that a sender
can sign a message using their private key, and the receiver can verify the signature using the
sender’s public key.
• Speed: The RSA technique is suited for usage in real-time applications since it is quite quick
and effective.
• Widely used: Online banking, e-commerce, and secure communications are just a few fields
and applications where the RSA algorithm is extensively developed.
Disadvantages:
• Slow processing speed: RSA algorithm is slower than other encryption algorithms, especially
when dealing with large amounts of data.
• Large key size: RSA algorithm requires large key sizes to be secure, which means that it
requires more computational resources and storage space.
• Vulnerability to side-channel attacks: RSA algorithm is vulnerable to side-channel attacks,
which means an attacker can use information leaked through side channels such as power
consumption, electromagnetic radiation, and timing analysis to extract the private key.
• Limited use in some applications: RSA algorithm is not suitable for some applications, such
as those that require constant encryption and decryption of large amounts of data, due to its
slow processing speed.
• Complexity: The RSA algorithm is a sophisticated mathematical technique that some
individuals may find challenging to comprehend and use.
• Key Management: The secure administration of the private key is necessary for the RSA
algorithm, although in some cases this can be difficult.
• Vulnerability to Quantum Computing: Quantum computers have the ability to attack the RSA
algorithm, potentially decrypting the data.
2.3 KEY MANAGEMENT
Key management refers to the processes and procedures involved in generating, storing, distributing,
and managing cryptographic keys used in cryptographic algorithms to protect sensitive data. It
ensures that keys used to protect sensitive data are kept safe from unauthorized access or loss. Good
key management helps maintain the security of encrypted information and is important for protecting
digital assets from cyber threats. Effective key management is crucial for ensuring the confidentiality,
integrity, and availability of encrypted information by securing cryptographic keys from unauthorized
access, loss, or compromise.
In symmetric key cryptography, a single shared key does both jobs, so the same key must be kept
secret between users. In asymmetric key cryptography, there are two keys: a public key that anyone
can use to encrypt messages or verify signatures, and a private key that only the owner uses to decrypt
messages or create signatures.
There are two aspects of Key Management:
1. Distribution of public keys.
2. Use of public-key encryption to distribute secrets.
Distribution of Public Key
The public key can be distributed in four ways:
1. Public announcement
2. Publicly available directory
3. Public-key authority
4. Public-key certificates.
1. Public Announcement: Here the public key is broadcast to everyone. The major
weakness of this method is a forgery. Anyone can create a key claiming to be someone
else and broadcast it. Until forgery is discovered can masquerade as claimed user.
2. Publicly Available Directory: In this type, the public key is stored in a public directory.
Directories are trusted here, with properties like Participant Registration, access and allow to
modify values at any time, contains entries like {name, public-key}. Directories can be
accessed electronically still vulnerable to forgery or tampering.
3. Public Key Authority: It is similar to the directory but, improves security by tightening
control over the distribution of keys from the directory. It requires users to know the public
key for the directory. Whenever the keys are needed, real-time access to the directory is made
by the user to obtain any desired public key securely.
4. Public Certification: This time authority provides a certificate (which binds an identity
to the public key) to allow key exchange without real-time access to the public authority each
time. The certificate is accompanied by some other info such as period of validity, rights of
use, etc. All of this content is signed by the private key of the certificate authority and it can
be verified by anyone possessing the authority’s public key. First sender and receiver both
request CA for a certificate which contains a public key and other information and then they
can exchange these certificates and can start communication.
The Diffie-Hellman key exchange (also known as exponential key exchange) is a method for securely
exchanging cryptographic keys over an insecure channel. It is a fundamental building block of many
secure communication protocols, including SSL/TLS and SSH.
The Diffie-Hellman key exchange works by allowing two parties (Alice and Bob) to agree on a shared
secret key over an insecure channel, without any other party being able to intercept the key or learn
anything about it. The key exchange involves the following steps −
• Alice and Bob agree on two large prime numbers, p and g, and a public key exchange algorithm.
• Alice chooses a secret integer, a, and computes A = g^a mod p. She sends A to Bob.
• Bob chooses a secret integer, b, and computes B = g^b mod p. He sends B to Alice.
• Alice computes s = B^a mod p. Bob computes s = A^b mod p.
• Alice and Bob now both have shared secret keys, which they can use to establish a secure
communication channel.
Where is Diffie-Hellman Key Exchange Used?
• Secure communication protocols − The Diffie-Hellman key exchange is used in many secure
communication protocols, such as SSL/TLS and SSH, to establish a secure channel between
two parties. It allows the parties to agree on a shared secret key that can be used to encrypt and
decrypt messages exchanged over the channel.
• Virtual private networks (VPNs) − The Diffie-Hellman key exchange is often used
in VPNs to establish a secure connection between a client and a server. It allows the client and
server to agree on a shared secret key that can be used to encrypt and decrypt traffic exchanged
over the VPN connection.
• Secure file transfer protocols − The Diffie-Hellman key exchange is used in many secure file
transfer protocols,such as SFTP and FTPS, to establish a secure channel for transferring files
between two parties.It allows the parties to agree on a shared secret key that can be used to
encrypt and decrypt the transferred files.
• Other applications − The Diffie-Hellman key exchange is also used in many other applications
where secure communication is required, such as secure email, secure web browsing, and
secure voice over IP (VoIP). It is a flexible and widely supported technique for establishing
secure communication channels.
• Alice and Bob agree on two large prime numbers, p and g, and a public key exchange algorithm.
• Alice chooses a secret integer, a, and computes A = g^a mod p. She sends A to Bob.
• Bob chooses a secret integer, b, and computes B = g^b mod p. He sends B to Alice.
• Alice computes s = B^a mod p. Bob computes s = A^b mod p.
• Alice and Bob now both have the shared secret key s, which they can use to establish a secure
communication channel.
Vulnerabilities of Diffie-Hellman Key Exchange
• Man-in-the-middle attacks − If an attacker is able to intercept and modify the messages
exchanged between Alice and Bob during the key exchange, they may be able to impersonate
Alice or Bob and establish a secure channel with the other party. This can be prevented by using
certificate-based authentication and/or by verifying the authenticity of the messages using
message authentication codes (MACs).
• Small subgroup attacks − If the prime number p used in the key exchange has a small
subgroup, an attacker may be able to use this to their advantage to recover the shared secret
key. To prevent this, it is important to use a large prime number with no known small
subgroups.
• Exponent attacks − If the secret exponents (a and b) used in the key exchange are not chosen
randomly, an attacker may be able to use this to their advantage to recover the shared secret
key. To prevent this, it is important to use a strong random number generator to generate the
secret exponents.
2.5 HASH FUNCTIONS
A hash function in cryptography is like a mathematical function that takes various inputs, like messages
or data, and transforms them into fixed-length strings of characters. Means the input to the hash function
is of any length but output is always of fixed length. This is like compressing a large balloon into a
compact ball.
The importance of this process lies in its generation of a unique "fingerprint" for each input. Any minor
alteration in the input results in a substantially different fingerprint, a quality known as "collision
resistance."
Hash functions play a crucial role in various security applications, including password storage (hash
values instead of passwords), digital signatures, and data integrity checks. Hash values, or message
digests, are values that a hash function returns.
• Hash functions are mathematical operations that "map" or change a given collection of data
into a fixed-length bit string that is referred to as the "hash value."
• Hash functions have a variety of complexity and difficulty levels and are used in cryptography.
• Cryptocurrency, password security, and communication security all use hash functions.
Properties of hash functions
Pre-Image Resistance
• This property says that given an input and its hash, it should be difficult to find another input
with the same hash.
• In other words, it should be challenging to find another input value y such that h(y) equals h(x)
if a hash function h for an input x returns the hash value h(x).
• This feature of the hash function protects against an attacker who wants to replace a new value
for the original input value and hash, but only holds the input value and its hash.
Collision Resistance
• This feature says that it should be difficult to identify two different inputs of any length that
produce the same hash. This characteristic is also known as a collision-free hash function.
• In other words, for a hash function h, it is difficult to identify two distinct inputs x and y such
that h(x)=h(y).
• A hash function cannot be free of collisions because it is a compression function with a set hash
length. The collision-free condition simply indicates that these collisions should be difficult to
locate.
• This characteristic makes it very hard for an attacker to identify two input values that have the
same hash.
• Furthermore, a hash function is second pre-image resistant if it is collision-resistant.
Efficiency of Operation
• Computation of h(x) for any hash function h given input x can be an easy process.
• Hash functions are computationally considerably faster than symmetric encryption.
Hashing generates an output of a specific length, regardless of the input size, and helps to make an
output of the same size from different input sizes.
Deterministic
For a given input, the hash function consistently produces the same output, like a recipe that always
yields the same dish when followed precisely.
Fast Computation
Hashing operations occur rapidly, even for large amounts of data sets.
Design of Hashing Algorithms
Hashing essentially involves a mathematical function that takes two data blocks of fixed size and
converts them into a hash code. The function is a key part of the hashing algorithm. The length of these
data blocks differ according to the algorithm used. Usually, they range from 128 bits to 512 bits.
Hashing algorithms use a sequence of rounds, similar to a block cipher, to process a message. In each
round, a fixed-size input is used, which usually combines the current message block and the result from
the previous round.
This process continues for multiple rounds until the entire message is hashed.
Due to the interconnected nature of hashing, where the output of one operation affects the input of the
next, even a minor change (a single bit difference) in the original message can drastically alter the final
hash value.
This phenomenon is known as the avalanche effect. Additionally, it's crucial to distinguish between a
hash function and a hashing algorithm. The hash function itself takes two fixed-length binary blocks of
data and generates a hash code.
A hashing algorithm, on the other hand, establishes how the message is divided into blocks and how
the outcomes of multiple hash operations are combined.
Popular Hash Functions
Hash functions play an important role in computing, providing versatile capabilities like: Quick retrieval
of data, Secure protection of information (cryptography), Ensuring data remains unaltered (integrity
verification). Some commonly used hash functions are −
For a number of years, MD5 was the most popular and often used hash function.
• The hash functions MD2, MD4, MD5, and MD6 are members of the MD family. It was adopted
as the RFC 1321, Internet Standard. It is a 128-bit hash function.
• In the software industry, MD5 digests are frequently used to ensure the integrity of transferred
files. To enable users to compare the checksum of the downloaded file with the pre-computed
MD5 checksum, file servers frequently provide this feature.
• In 2004, collisions were found in MD5. It was claimed that an analytical attack using a
computer cluster was successful in under one hour. Since MD5 was compromised by this
collision attack, using it is no longer recommended.
The four SHA algorithms which make up the SHA family are SHA-0, SHA-1, SHA-2, and SHA-3.
Despite coming from the same family, the structure of it differs.
• The National Institute of Standards and Technology (NIST) released the first iteration of the
160-bit hash algorithm, known as SHA-0, in 1993. It did not gain much popularity and had few
drawbacks. SHA-1 was created later in 1995 to address perceived flaws in SHA-0.
• SHA-1 is the most widely used of the existing SHA hash functions. It is used in most of the
applications and protocols including Secure Socket Layer (SSL) security.
• In 2005, a technique was discovered for SHA-1 collision detection that can be used in a realistic
time frame. So it is doubtful on SHA-1's long-term usability.
• SHA-224, SHA-256, SHA-384, and SHA-512 are the other four SHA variants in the SHA-2
family, which vary based on the number of bits in their hash value. The SHA-2 hash function
has not yet been the target of any effective attacks
• Though SHA-2 is a strong hash function. Though significantly different, its basic design still
follows the design of SHA-1. NIST thus demanded the creation of new competitive hash
function designs.
• The Keccak algorithm was selected by the NIST in October 2012 to replace the SHA-3
standard. Keccak has several advantages, including effective operation and strong attack
resistance.
3. CityHash
CityHash is another non-cryptographic hash function that is designed for fast hashing of large amounts
of data. It is optimized for modern processors and offers good performance on both 32-bit and 64-bit
architectures.
4.BLAKE2
BLAKE2 is a fast and secure hash function that improves upon SHA-3. It is widely used in applications
like cryptocurrency mining that need fast hashing. There are two types of BLAKE2 −
• BLAKE2b − Best for 64-bit computers, it produces hash values up to 512 bits long.
• BLAKE2s − Best for smaller computers (8-32 bits), it produces hash values up to 256 bits long.
CRC (Cyclic Redundancy Check) is a technique used to detect errors in data transfer. It involves adding
a special value called a checksum to the end of a message. This checksum is calculated based on the
message's content and is included during transmission.
When the data is received, the recipient recalculates the checksum using the same method. If the new
checksum matches the original one, it's likely that the message was transmitted without errors. While
CRC is effective for error detection, it's not a security measure. It is primarily used to ensure the integrity
of data during transmission, not to protect it from unauthorized access or modification.
SHA-1 or Secure Hash Algorithm 1 is a cryptographic algorithm which takes an input and produces
a 160-bit (20-byte) hash value. This hash value is known as a message digest. This message digest is
usually then rendered as a hexadecimal number which is 40 digits long.
It is a U.S. Federal Information Processing Standard and was designed by the United States National
Security Agency. SHA-1 is now considered insecure since 2005. Major tech giants browsers like
Microsoft, Google, Apple and Mozilla have stopped accepting SHA-1 SSL certificates by 2017.
To calculate cryptographic hashing value in Java, MessageDigest Class is used, under the
package java.security. MessageDigest Class provides following cryptographic hash function to find
hash value of a text as follows:
• MD2
• MD5
• SHA-1
• SHA-224
• SHA-256
• SHA-384
• SHA-512
These algorithms are initialized in static method called getInstance(). After selecting the algorithm
the message digest value is calculated and the results are returned as a byte array. BigInteger class is
used, to convert the resultant byte array into its signum representation.
Applications:
• Cryptography: The main application of SHA1 is to protect communications from
being intercepted by outside parties. From a given data input, SHA1 generates a fixed-
size, singular, and irreversible hash value. The integrity of the data can then be confirmed
by comparing this hash value to the original hash value. This makes it possible to confirm
that the data was not changed or tampered with in any manner during transmission.
• Data Integrity: In many industries, such as finance, healthcare, and government, data
integrity is a major concern. Data integrity in a system is checked using the SHA1
algorithm. A fingerprint of the original data is created using a hash value produced by
the SHA1 algorithm. If the data changes in any way, the hash value will also change,
indicating that the data has been tampered with.
• Digital Signatures: Digital signatures are used to confirm the legitimacy of digital
documents and messages. The digital document or communication is hashed using the
SHA1 technique, and its hash value is subsequently encrypted with the sender’s private
key. Using the sender’s public key to decode the message, the recipient can then compare
the hash value to the original value.
• Digital Forensics: In digital forensics, a hash of a file containing digital evidence can
be produced using the SHA1 algorithm. To ensure that the evidence hasn’t been altered
with during the investigation, utilize this hash value as proof. It gives proof that the file
has not been altered if the hash values of the original file and the evidence file match.
• Password Storage: SHA1 can be used to save passwords. A hash of the password is
generated using SHA1 when a user creates a password. The password itself is then
substituted in a database for the hash value. The user’s password is hashed with SHA1
when they attempt to log in, and the resulting hash is compared to a previously generated
hash.
• Software Updates: The integrity of software updates can be guaranteed using SHA1.
The SHA1 hash of the update file can be made public on the software vendor’s website
when an update is made available. By comparing the hash of the downloaded file with
the published hash, users can download the update and ensure its integrity.