Coding Encrypted Chat in Python

  Рет қаралды 43,144

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 3 ай бұрын
exactly what i was looking, keep the good work.
@zabij_s5123
@zabij_s5123 4 ай бұрын
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.
@Solexdballer
@Solexdballer Жыл бұрын
Stay Blessed Man. Tnx Alot
@tiwaztyr4324
@tiwaztyr4324 Жыл бұрын
Thank you for all the valuable content!
@shubham8192
@shubham8192 6 ай бұрын
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 3 ай бұрын
very good explanation, thanks
@15.AAYUSHI-lm3su
@15.AAYUSHI-lm3su 8 ай бұрын
thankyou sir
@ashhunter-ji5dm
@ashhunter-ji5dm Жыл бұрын
Great tutorial, I wonder can we send a message to someone over the internet just by using Socket and P2P?
@Eisblume2000
@Eisblume2000 Жыл бұрын
i dont even know how to code, but your explanations are so amazing i keep watching your vids
@noahlantz9938
@noahlantz9938 5 ай бұрын
awesome video
@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
@TecheNology
@TecheNology 10 ай бұрын
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...
@vidya-laxmi
@vidya-laxmi Жыл бұрын
Cool !
@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 5 ай бұрын
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 5 ай бұрын
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()
@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 6 ай бұрын
RSA is widely used and its considered more safe as compared to others
@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 4 ай бұрын
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.
@artaxerxes360
@artaxerxes360 5 ай бұрын
Do one with ssl please, having a hard time just validating the certificate
@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?
@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!
@caxstation
@caxstation 8 ай бұрын
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 4 ай бұрын
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.
@shahedhamami8739
@shahedhamami8739 11 ай бұрын
Why the sending message function dose'nt work plzz what can i do ?
@caionggabriel607
@caionggabriel607 7 ай бұрын
How connect with other rede?
@SheetalIB
@SheetalIB 2 ай бұрын
where can i get source code
@Toxtroll
@Toxtroll 6 ай бұрын
source code????
@myt436
@myt436 8 ай бұрын
Everything you claim is true, the chat is encrypted. It's a shame it's not also secure. :(
@kadaliakshay6770
@kadaliakshay6770 Жыл бұрын
REQUEST!!!!: Can u pleaseeeeeeeeeeeeeeeeeee give me the code
@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 Live Chat Room Tutorial Using Flask & SocketIO
1:19:28
Tech With Tim
Рет қаралды 71 М.
The Noodle Stamp Secret 😱 #shorts
00:30
Mr DegrEE
Рет қаралды 52 МЛН
I PEELED OFF THE CARDBOARD WATERMELON!#asmr
00:56
HAYATAKU はやたく
Рет қаралды 34 МЛН
ISSEI funny story😂😂😂Strange World | Pink with inoCat
00:36
ISSEI / いっせい
Рет қаралды 29 МЛН
Зу-зу Күлпәш. Агроном. (5-бөлім)
55:20
ASTANATV Movie
Рет қаралды 653 М.
Python Sockets Simply Explained
39:33
NeuralNine
Рет қаралды 150 М.
RSA Encryption From Scratch - Math & Python Code
43:30
NeuralNine
Рет қаралды 25 М.
5 Useful Dunder Methods In Python
16:10
Indently
Рет қаралды 46 М.
Simple GUI Chat in Python
35:56
NeuralNine
Рет қаралды 172 М.
Encrypted File Transfer via Sockets in Python
19:54
NeuralNine
Рет қаралды 19 М.
GPT-4o Deep Dive & Hidden Abilities you should know about
28:11
Advanced TCP Chat Room in Python
37:23
NeuralNine
Рет қаралды 52 М.
📱 SAMSUNG, ЧТО С ЛИЦОМ? 🤡
0:46
Яблочный Маньяк
Рет қаралды 1 МЛН
Why spend $10.000 on a flashlight when these are $200🗿
0:12
NIGHTOPERATOR
Рет қаралды 17 МЛН
Пленка или защитное стекло: что лучше?
0:52
Слава 100пудово!
Рет қаралды 1,8 МЛН
Я Создал Новый Айфон!
0:59
FLV
Рет қаралды 3,3 МЛН