Coding Encrypted Chat in Python

  Рет қаралды 42,246

NeuralNine

NeuralNine

Күн бұрын

Today we learn how to build an encrypted chat in Python.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine.com/books/
💻 The Algorithm Bible Book: www.neuralnine.com/books/
👕 Programming Merch: www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine.com/
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/NeuralNine
🎙 Discord: / discord
🎵 Outro Music From: www.bensound.com/
Timestamps:
(0:00) Intro
(0:15) Coding Encrypted Chat
(14:12) Analyzing Traffic in Wireshark
(19:59) Outro

Пікірлер: 47
@paulthomas1052
@paulthomas1052 Жыл бұрын
Great explanation and practical code. Thanks :)
@Minussa9527
@Minussa9527 2 ай бұрын
exactly what i was looking, keep the good work.
@Solexdballer
@Solexdballer Жыл бұрын
Stay Blessed Man. Tnx Alot
@zabij_s5123
@zabij_s5123 3 ай бұрын
love it! great explanation man
@allenseay2036
@allenseay2036 Жыл бұрын
Best explanation of encryption that I have ever heard! Clear, simple, and concise!
@user-zg5le6bg2s
@user-zg5le6bg2s 11 ай бұрын
Great tutorial! Congrats
@Darakon
@Darakon Жыл бұрын
Very cool! Thanks.
@shubham8192
@shubham8192 5 ай бұрын
thank you so much man, I use your code for my college project about public key cryptography
@sebastiangonzales46
@sebastiangonzales46 3 ай бұрын
thesis?
@ashwiniashwini886
@ashwiniashwini886 Ай бұрын
Hlo sir if your project is over then u can share ?
@paulinobrito9161
@paulinobrito9161 2 ай бұрын
very good explanation, thanks
@adarsham4333
@adarsham4333 Жыл бұрын
This guy kinda looks like Michael Scofield from Prison Break. But the topics and his style of explaining both are really good.
@brunoruiztalamo3692
@brunoruiztalamo3692 11 ай бұрын
He should show us his back just in case
@tiwaztyr4324
@tiwaztyr4324 Жыл бұрын
Thank you for all the valuable content!
@15.AAYUSHI-lm3su
@15.AAYUSHI-lm3su 8 ай бұрын
thankyou sir
@Eisblume2000
@Eisblume2000 Жыл бұрын
i dont even know how to code, but your explanations are so amazing i keep watching your vids
@vidya-laxmi
@vidya-laxmi Жыл бұрын
Cool !
@ashhunter-ji5dm
@ashhunter-ji5dm Жыл бұрын
Great tutorial, I wonder can we send a message to someone over the internet just by using Socket and P2P?
@noahlantz9938
@noahlantz9938 5 ай бұрын
awesome video
@punchcake4832
@punchcake4832 Жыл бұрын
the matlab joke made me crack lmao
@Rascherx
@Rascherx Жыл бұрын
Great video! I have a question: what if some third party will be able to intercept the public keys? I'm talking about the man-in-the-middle (MITM) problem. How to deal with that kind of threat?
@steves9250
@steves9250 Жыл бұрын
Only the public key is sent. To decode it you need the private key. In a full solution the two sides exchange public keys and then use the other sides public key to send, and their own private key to decode the received messages. In a MITM attack the attacker could replace the public keys and then decode each message with their own private key and then reencode the message with original public key but this can be detected by including a copy of the public key, or something derived from it, in an encoded message so that the key the receiver is using is different to this new copy since the attacker had to replace the original. Look into Diffie Hellman key exchange.
@rikkilleen3169
@rikkilleen3169 Жыл бұрын
@@steves9250 I just got done with a 3 week course for Sec+ course the Army put me through. You're giving me flashbacks! 😝
@Stopinvadingmyhardware
@Stopinvadingmyhardware Жыл бұрын
@@steves9250 The MITM on needs enough packets to break the encryption.
@originalbinaryhustler3876
@originalbinaryhustler3876 4 ай бұрын
use https socks 5 and ssl port 443 add AES encryption with a SHA 256 hash 128b as your keys, To further add security create a firewall which controls incoming and outgoing traffic, make sure you get your logs game tight This should ensure End to End encryption in the manner you are seeking
@originalbinaryhustler3876
@originalbinaryhustler3876 4 ай бұрын
here is an example of how you can start off: import socket import threading import rsa from Crypto.Cipher import AES from Crypto.Random import get_random_bytes import ssl public_key, private_key = rsa.newkeys(1024) public_partner = None aes_key = get_random_bytes(16) choice = input('Do you want to host (1) or join a chat (2)? ') IP = input('Enter the IP of the server: ') PORT = int(input('Enter the port of the server: ')) context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) context.load_cert_chain(certfile='path/to/certfile', keyfile='path/to/keyfile') if choice == '1': server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind((IP, PORT)) server.listen() client, _ = server.accept() client = context.wrap_socket(client, server_side=True) client.send(public_key.save_pkcs1('PEM')) public_partner = rsa.PublicKey.load_pkcs1(client.recv(1024), 'PEM') encrypted_aes_key = rsa.encrypt(aes_key, public_partner) client.send(encrypted_aes_key) elif choice == '2': client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client = context.wrap_socket(client) client.connect((IP,PORT)) public_partner = rsa.PublicKey.load_pkcs1(client.recv(1024), 'PEM') encrypted_aes_key = client.recv(1024) aes_key = rsa.decrypt(encrypted_aes_key, private_key) client.send(public_key.save_pkcs1('PEM')) else: exit() def sending_messages(c): while True: message = input('') cipher = AES.new(aes_key, AES.MODE_EAX) ciphertext, tag = cipher.encrypt_and_digest(message.encode()) c.send(ciphertext + tag) print('You: ' + message) def receiving_messages(c): while True: ciphertext = c.recv(1024) cipher = AES.new(aes_key, AES.MODE_EAX, nonce=ciphertext[:16]) message = cipher.decrypt_and_verify(ciphertext[16:-16], ciphertext[-16:]) print('User:' + message.decode()) threading.Thread(target=sending_messages, args=(client,)).start() threading.Thread(target=receiving_messages, args=(client,)).start()
@TecheNology
@TecheNology 9 ай бұрын
Hi neural I have been following your videos and you are really very specific. I have a problem with this chat, client and server only communicate if I'm on the same network. Come faccio comunicare client e serve anche su reti esterne? Ho provato col port forwarding ad aprire la mia porta, inserire ip locale e nel client l ip pubblico, ma non si connette, non riesco a capire il problema...
@sahmyvig7082
@sahmyvig7082 9 ай бұрын
This is great as I can use it to show implementation of Encryption. However, is it only RSA I can use for this? I want to build a secure messaging protocol as school project. Can I use any encryption or it has to be RSA. Also if you have any tips or suggestions for this project, I'd really appreciate. Thanks
@shubham8192
@shubham8192 5 ай бұрын
RSA is widely used and its considered more safe as compared to others
@tcgvsocg1458
@tcgvsocg1458 Жыл бұрын
its really interesting you allready show how to send message but still good video...can you do a video where you create a mini rythm game?
@vedkhetle7318
@vedkhetle7318 9 ай бұрын
how can i do MITM in this?
@artaxerxes360
@artaxerxes360 5 ай бұрын
Do one with ssl please, having a hard time just validating the certificate
@zFede_Rico
@zFede_Rico Жыл бұрын
can i ask something? if i have the client on one pc and the server on the other, so they are in 2 different files, and to receive messages i need to decrypt them with the private key wich is not shared between client and server and only the server has, how do i receive messages on the client?
@MasterPuppets206
@MasterPuppets206 3 ай бұрын
There are 4 keys total in this example. The server has a public and private key and so does the client. All the scripts do is connect to each other and exchange public keys before sending and receiving messages. Each instance only has their respective public and private keys until they connect to each other and store the other's public key.
@scottlee38
@scottlee38 Жыл бұрын
Any idea how to get around the (Super Long Message Error) at the end?
@abdullahmalik3818
@abdullahmalik3818 5 ай бұрын
I am a bit late but you can increase the number of bits from 1024 to some big numbers to handle large messages
@scottlee38
@scottlee38 5 ай бұрын
@@abdullahmalik3818 Awesome, I will give it a try. Thanks!
@caionggabriel607
@caionggabriel607 6 ай бұрын
How connect with other rede?
@shahedhamami8739
@shahedhamami8739 10 ай бұрын
Why the sending message function dose'nt work plzz what can i do ?
@SheetalIB
@SheetalIB 2 ай бұрын
where can i get source code
@caxstation
@caxstation 7 ай бұрын
Great video and content! Just one observation: I don't know if was on purpose or not, but you didn't inspect the first package sent between the 2 chats when you launch with option 1 and 2 (the exchange of the keys). I'm not sure how it works that and didn't try yet this simple implementation, but I believe the 2 keys were exchanged in clear text (correct me if I'm wrong :D ) which means that someone catching the 2 keys exchanged could use it to decrypt the messages. A suggestion as a content video would be how to improve this would be how to exchange keys with Diffie-Hellman method. Keep up the good work!
@MasterPuppets206
@MasterPuppets206 3 ай бұрын
You can't use public keys to decrypt messages, only to encrypt them. The Diffie-Hellman method doesn't protect against man in the middle attacks. You would need to add another layer of security to verify the users' identities.
@Toxtroll
@Toxtroll 6 ай бұрын
source code????
@kadaliakshay6770
@kadaliakshay6770 Жыл бұрын
REQUEST!!!!: Can u pleaseeeeeeeeeeeeeeeeeee give me the code
@myt436
@myt436 7 ай бұрын
Everything you claim is true, the chat is encrypted. It's a shame it's not also secure. :(
@Joseph-ws5de
@Joseph-ws5de Жыл бұрын
Were is the source code ?
@JNET_Reloaded
@JNET_Reloaded Жыл бұрын
wheres the github for this please i wana test it out?
WHOIS Domain Lookup Tool in Python
8:00
NeuralNine
Рет қаралды 10 М.
Python Sockets Simply Explained
39:33
NeuralNine
Рет қаралды 148 М.
ФОКУС С ЧИПСАМИ (секрет)
00:44
Masomka
Рет қаралды 4 МЛН
Ages 1 - 100 Decide Who Wins $250,000
40:02
MrBeast
Рет қаралды 126 МЛН
КАК ГЛОТАЮТ ШПАГУ?😳
00:33
Masomka
Рет қаралды 2,1 МЛН
End to End Encryption (E2EE) - Computerphile
8:12
Computerphile
Рет қаралды 739 М.
7 Cryptography Concepts EVERY Developer Should Know
11:55
Fireship
Рет қаралды 1,2 МЛН
Python Asynchronous Programming - AsyncIO & Async/Await
25:57
Tech With Tim
Рет қаралды 408 М.
Learning Python - Pointers
4:49
Code Militia
Рет қаралды 18 М.
The Truth About Learning Python in 2024
9:38
Internet Made Coder
Рет қаралды 77 М.
RSA Encryption From Scratch - Math & Python Code
43:30
NeuralNine
Рет қаралды 24 М.
Modern Graphical User Interfaces in Python
11:12
NeuralNine
Рет қаралды 1,4 МЛН
BASH scripting will change your life
14:18
NetworkChuck
Рет қаралды 983 М.
How To Design A Completely Unbreakable Encryption System
5:51
Half as Interesting
Рет қаралды 469 М.
End-to-end Message Encryption
15:57
Arpit Bhayani
Рет қаралды 14 М.
Broken Flex Repair #technology #mobilerepair
0:55
ideal institute aligarh
Рет қаралды 16 МЛН
ИГРОВОЙ ПК от DEXP за 37 тысяч рублей из DNS
27:53