SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
Cryptography	in	Python
1
Amirali Sanatinia
amirali@ccs.neu.edu
Northeastern	University
Cryptography
• Cryptography	is	ubiquitous	today
• From	mobile	phones	to	wireless	connections
• Supported	in	almost	every	programming	language
• It	is	even	embedded	in	the	CPUs
• It	is	not	hard	to	do	crypto	right	but	…
2
Crypto	Failures
3
Encryption	Models
4
Encryption
Algorithm
Decryption
Algorithm
Encryption
Key
Decryption
Key
Message
Destination
Plaintext Ciphertext Plaintext
Symmetric encryption:
Asymmetric encryption:
Public key
Shared key Shared key
Private key
Symmetric	vs.	Asymmetric	Encryption
• Symmetric	algorithms	are	much	faster	
– In	the	order	of	a	1000	times	faster
• Symmetric	algorithms	require	a	shared	secret
– Impractical	if	the	communicating	entities	don’t	have	another	secure	
channel
• Both	algorithms	are	combined	to	provide	practical	and	
efficient	secure	communication
– E.g.,	establish	a	secret	session	key	using	asymmetric	crypto	and	use	
symmetric	crypto	for	encrypting	the	traffic
5
Advanced	Encryption	Standard	(AES)
• Also	known	as	Rijndael
• Part	of	NIST	competition
• Requirements
– Fast	in	software	and	hardware
– Block	size:	128;	Key	size:	128,	192	and	256
• Joan	Daemen and	Vincent	Rijmen
• First	published	in	1998
• FIPS	197	on	November	26,	2001
• Other	candidates:	Mars,	RC6,	Serpent,	Twofish
6
Block	Cipher	Mode	of	Operation
• AES	works	on	a	block	of	data	(128	bits)
• To	encrypt	a	large	message,	each	block	needs	
to	be	encrypted
• Different	modes	of	encrypting	the	blocks
– Electronic	Codebook	(ECB)
– Cipher	Block	Chaining	(CBC)
– Counter	(CTR)
7
ECB	vs.	CBC
8
Original ECB CBC
RSA
• One	of	the	first	practical	public	crypto	systems
• Designed	by	Ron	Rivest,	Adi Shamir,	and	
Leonard	Adleman
• First	published	in	1977
• Was	patented	until	September	2000
• Based	on	the	hardness	of	factoring	problem	
and	modular	arithmetic
9
Textbook	RSA
• E(M)	=	Me
mod	n =	C (Encryption)
• D(C)	=	Cd
mod	n =	M (Decryption)
• RSA	parameters	and	basic	(not	secure)	operations:
– p,	q,	two	big	prime	numbers (private,	chosen)
– n =	pq,	f(n)	=	(p-1)(q-1) (public,	calculated)
– e,	with	gcd(f(n),	e)	=	1,		1<e<f(n) (public,	chosen)
– d	=	e-1
mod	f(n) (private,	calculated)
• D(E(M))	=	Med	
mod	n	=	M	kf(n)+1	
=	M (Euler’s	theorem)
10
Example	of	RSA
• Keys	generation:
– p =	5;	q =	11	=>	n =	55
– e =	3	=>	d =	27
• Because	ed =	1	mod	(p-1)(q-1)
– Public	key:	(e,	n);	Private	Key:	(d,	n)
• Encryption
– M =	2
– Encryption(M)	=	Me mod	n =	8
– Decryption(8)	=	8d mod	n =	2	
11
Hashing	Functions
• Input:	long	message
• Output:	short	block	(called	hash or	message	digest)
• Desired	properties:	
– Pre-image:	Given	a	hash	h it	is	computationally	infeasible	to	find	
a	message	m that	produces	h
– Second	preimage:	Given	message	m,	it	is	computationally	
infeasible	to	find	a	message	m’,	(m	≠	m’)	such	that,	h(m)	=	h(m’)
– Collisions:	It	is	computationally	difficult	to	find	any	two	
messages	m,	m’	(m	≠	m’)	such	that,	h(m)	=	h(m’)
• Examples
– Recommended	Hash	Algorithm	(SHA-2,	SHA-3)	by	NIST
– SHA-1:	output	160	bits	being	phased	out
– MD2,	MD4,	and	MD5	by	Ron	Rivest [RFC1319,	1320,	1321]
12
Python	Crypto	Libraries
• PyCrypto
– Oldest	and	most	widely	used
• M2Crypto
– SWIG	binding
• Cryptography*
– PY2,	PY3,	PyPy
– OpenSSL	CFFI	binding
• PyNaCl ,	python-nss,	etc.
13
Cryptography	In	Action
(SHA2)
14
Cryptography	In	Action
(AES	Encryption/Decryption)
15
Cryptography	In	Action
(RSA	Key	Generation)
16
Cryptography	In	Action
(RSA	Encryption/Decryption)
17
Cryptography	In	Action
(Fernet)
18
• Provides	authenticated	encryption
– AES	in	CBC	mode,	128	bit	key,	PKCS7	padding
– SHA256	HMAC	for	authentication
Takeaways
• Don’t	invent	your	own	crypto	algorithm
• Don’t	implement	your	own	crypto	library
• Doing	crypto	in	a	right	way	is	not	difficult
• Use	SSL	for	data	in	transit
• Use	PGP	for	data	at	rest
19
Thank	You!
Questions?
20

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Password based cryptography
Password based cryptographyPassword based cryptography
Password based cryptography
 
Overview of cryptography
Overview of cryptographyOverview of cryptography
Overview of cryptography
 
Cryptography
CryptographyCryptography
Cryptography
 
Cryptography and network security Nit701
Cryptography and network security Nit701Cryptography and network security Nit701
Cryptography and network security Nit701
 
Cryptography.ppt
Cryptography.pptCryptography.ppt
Cryptography.ppt
 
Advanced encryption standard (aes)
Advanced encryption standard (aes)Advanced encryption standard (aes)
Advanced encryption standard (aes)
 
Cryptography
CryptographyCryptography
Cryptography
 
Ipsec
IpsecIpsec
Ipsec
 
RSA ALGORITHM
RSA ALGORITHMRSA ALGORITHM
RSA ALGORITHM
 
Cryptography
CryptographyCryptography
Cryptography
 
Cryptography
CryptographyCryptography
Cryptography
 
symmetric key encryption algorithms
 symmetric key encryption algorithms symmetric key encryption algorithms
symmetric key encryption algorithms
 
Cryptography
CryptographyCryptography
Cryptography
 
Ch03 block-cipher-and-data-encryption-standard
Ch03 block-cipher-and-data-encryption-standardCh03 block-cipher-and-data-encryption-standard
Ch03 block-cipher-and-data-encryption-standard
 
Cryptography - 101
Cryptography - 101Cryptography - 101
Cryptography - 101
 
Cryptography and Network Security
Cryptography and Network SecurityCryptography and Network Security
Cryptography and Network Security
 
RC4&RC5
RC4&RC5RC4&RC5
RC4&RC5
 
Cryptography
CryptographyCryptography
Cryptography
 
Cryptography Fundamentals
Cryptography FundamentalsCryptography Fundamentals
Cryptography Fundamentals
 
Cryptography Intro
Cryptography IntroCryptography Intro
Cryptography Intro
 

Similar a Cryptography in Python (20)

Cryptography
CryptographyCryptography
Cryptography
 
Lecture 5 - Cryptography.pptx
Lecture 5 - Cryptography.pptxLecture 5 - Cryptography.pptx
Lecture 5 - Cryptography.pptx
 
Cryptology - The practice and study of hiding information
Cryptology - The practice and study of hiding informationCryptology - The practice and study of hiding information
Cryptology - The practice and study of hiding information
 
Basic Cryptography.pdf
Basic Cryptography.pdfBasic Cryptography.pdf
Basic Cryptography.pdf
 
Security
SecuritySecurity
Security
 
CISSP - Chapter 3 - Cryptography
CISSP - Chapter 3 - CryptographyCISSP - Chapter 3 - Cryptography
CISSP - Chapter 3 - Cryptography
 
Cryptography : The Art of Secured Messaging
Cryptography : The Art of Secured MessagingCryptography : The Art of Secured Messaging
Cryptography : The Art of Secured Messaging
 
groupWork.pptx
groupWork.pptxgroupWork.pptx
groupWork.pptx
 
Lec # 7 Symmetric and asymmetric cryptography.pptx
Lec # 7 Symmetric and asymmetric cryptography.pptxLec # 7 Symmetric and asymmetric cryptography.pptx
Lec # 7 Symmetric and asymmetric cryptography.pptx
 
Cryptography and network security
Cryptography and network security Cryptography and network security
Cryptography and network security
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network security
 
Network security
Network securityNetwork security
Network security
 
symmetric cipher model.pptx
symmetric cipher model.pptxsymmetric cipher model.pptx
symmetric cipher model.pptx
 
Cryptography.pptx
Cryptography.pptxCryptography.pptx
Cryptography.pptx
 
Security fundamentals
Security fundamentalsSecurity fundamentals
Security fundamentals
 
Security Fundamentals
Security FundamentalsSecurity Fundamentals
Security Fundamentals
 
Encryption algorithms
Encryption algorithmsEncryption algorithms
Encryption algorithms
 
Cryptography
Cryptography Cryptography
Cryptography
 
Introduction to cryptography part1-final
Introduction to cryptography  part1-finalIntroduction to cryptography  part1-final
Introduction to cryptography part1-final
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 

Último

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Último (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

Cryptography in Python