األمن السيبراني
د/عبدالملك الحميري
Chapter 5: Publickey
Cryptography & RSA
2
▪ As we discussed before, Cryptography is a method of how to keep a message
secure(develop ciphers that are unbreakable)
▪ Cryptography techniques are:
3
▪ Asymmetric key cryptography is a branch of cryptography where a secret
key can be divided into two parts, a public key and a private key. The public
key can be given to anyone, trusted or not, while the private key must be kept
secret (just like the key in symmetric cryptography).
▪ Sender and receiver use different keys to encrypt and decrypt the message.
▪ It is also called as public key cryptography.
4
5
قدم التشفير باستخدام المفتاح العام طريقة تختلف تماماً عن التشفير المتناظر. ▪
ال يوجد مفتاح سري مشترك بين المرسل والمستقبل منذ البداية ،وإنما يستخدمان مفتاحان منفصالن. ▪
يستخدم أحدهما للتشفير واألخر لفك التشفير. ▪
في هذا النوع من التشفير ،يولد كل مستخدم زوجاً من المفاتيح مرتبطين ببعضهما (بطريقة معقدة ال ▪
عرف االخر) أحدهما عام ويوضع في سجل (مجلد) عام يمكن االطالع تسمح بكشف أي منهما إذا ُ
عليه من قبل جميع المستخدمين ،واألخر خاص ويُعد مفتاحاً سرياً خاصاً بالمستخدم ويجب اال يطلع
عليه االخرون .ثم بعد ذلك تتم عمليتا التشفير وفك التشفير كما هو موضح في الشكل التالي.
6
Advantages and Disadvantages of Asymmetric Key Cryptography:
▪ Advantages:
✓ It is more robust.
✓ It is less susceptible to third-party security breach attempts.
▪ Disadvantages:
✓ It involves high computational requirements.
✓ It is slower than symmetric key cryptography.
7
Use Cases of Public-Key Cryptography
▪ SSH
▪ HTTPS, formerly SSL
▪ Bitcoin
▪ Authentication
8
Symmetric Encryption Asymmetric Encryption
Uses a single key to encrypt and decrypt the Uses two separate keys for encryption and
data. decryption. They’re known as “public key”ً
and “private key.”
Is more straightforward and conventional Was invented to mitigate the risks of
method of encryption. symmetric encryption and is more
complicated.
Is faster when compared to asymmetric Is slower and requires more computational
encryption, thanks to its simplicity. power because of its complexity.
Requires smaller key lengths Asymmetric keys are longer in their lengths.
Provides the confidentiality of the data (data Provides confidentiality, authenticity, and
security). non-repudiation.
Is useful for encrypting a large amount of Is useful for encrypting a small amount of
data. data.
Standard symmetric encryption algorithms Standard asymmetric encryption algorithms
are RC4, AES, DES, 3DES, and QUAD. are RSA, Diffie-Hellman, ECC, El Gamal,
9 and DSA.
RSA: getting ready
message: just a bit pattern
bit pattern can be uniquely represented by an integer
number
thus, encrypting a message is equivalent to encrypting a
number.
example:
m= 10010001 . This message is uniquely represented by the
decimal number 145.
to encrypt m, we encrypt the corresponding number, which
gives a new number (the ciphertext).
Network Security
RSA: Creating public/private key pair
1. choose two large prime numbers p, q.
(e.g., 1024 bits each)
2. compute n = pq, z = (p-1)(q-1)
3. choose e (with e<n) that has no common factors
with z (e, z are “relatively prime”).
4. choose d such that ed-1 is exactly divisible by z.
(in other words: ed mod z = 1 ).
5. public key is (n,e). private key is (n,d).
+ -
KB KB
Network Security
RSA: encryption, decryption
0. given (n,e) and (n,d) as computed above
1. to encrypt message m (<n), compute
c = m e mod n
2. to decrypt received bit pattern, c, compute
m = c d mod n
magic m = (me mod n) d mod n
happens!
c
Network Security
RSA example:
Bob chooses p=5, q=7. Then n=35, z=24.
e=5 (so e, z relatively prime).
d=29 (so ed-1 exactly divisible by z).
encrypting 8-bit messages.
bit pattern m me c = me mod n
encrypt:
00001100 12 24832 17
d
c c m = cd mod n
decrypt:
17 481968572106750915091411825223071697 12
Network Security
RSA Example
Network Security
Why is RSA secure?
suppose you know Bob’s public key (n,e). How hard
is it to determine d?
essentially need to find factors of n without
knowing the two factors p and q
fact: factoring a big number is hard
Network Security
RSA in practice: session keys
exponentiation in RSA is computationally intensive
DES is at least 100 times faster than RSA
use public key crypto to establish secure
connection, then establish second key – symmetric
session key – for encrypting data
session key, KS
Bob and Alice use RSA to exchange a symmetric key KS
once both have KS, they use symmetric key
cryptography
Network Security