Coding Encrypted Chat in Python

Поділитися
Вставка
  • Опубліковано 19 січ 2025

КОМЕНТАРІ • 50

  • @allenseay2036
    @allenseay2036 2 роки тому +2

    Best explanation of encryption that I have ever heard! Clear, simple, and concise!

  • @Minussa9527
    @Minussa9527 11 місяців тому +1

    exactly what i was looking, keep the good work.

  • @adarsham4333
    @adarsham4333 2 роки тому +5

    This guy kinda looks like Michael Scofield from Prison Break. But the topics and his style of explaining both are really good.

  • @shubham8192
    @shubham8192 Рік тому +3

    thank you so much man,
    I use your code for my college project
    about public key cryptography

  • @paulthomas1052
    @paulthomas1052 2 роки тому +5

    Great explanation and practical code. Thanks :)

  • @zabij_s
    @zabij_s Рік тому

    love it! great explanation man

  • @zFede_Rico
    @zFede_Rico 2 роки тому +2

    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 Рік тому

      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.

  • @paulinobrito9161
    @paulinobrito9161 11 місяців тому

    very good explanation, thanks

  • @Rascherx
    @Rascherx 2 роки тому +5

    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 2 роки тому +5

      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 2 роки тому +1

      @@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 2 роки тому

      @@steves9250 The MITM on needs enough packets to break the encryption.

    • @originalbinaryhustler3876
      @originalbinaryhustler3876 Рік тому

      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 Рік тому

      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()

  • @AndersonVanin-i9e
    @AndersonVanin-i9e Рік тому +1

    Great tutorial! Congrats

  • @ashhunter-ji5dm
    @ashhunter-ji5dm Рік тому +1

    Great tutorial, I wonder can we send a message to someone over the internet just by using Socket and P2P?

  • @tiwaztyr4324
    @tiwaztyr4324 2 роки тому +2

    Thank you for all the valuable content!

  • @artaxerxes360
    @artaxerxes360 Рік тому +1

    Do one with ssl please, having a hard time just validating the certificate

  • @punchcake4832
    @punchcake4832 2 роки тому +1

    the matlab joke made me crack lmao

  • @scottlee38
    @scottlee38 2 роки тому +2

    Any idea how to get around the (Super Long Message Error) at the end?

    • @abdullahmalik3818
      @abdullahmalik3818 Рік тому

      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 Рік тому

      @@abdullahmalik3818 Awesome, I will give it a try. Thanks!

  • @sahmyvig7082
    @sahmyvig7082 Рік тому +1

    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 Рік тому

      RSA is widely used and its considered more safe as compared to others

  • @Solexdballer
    @Solexdballer 2 роки тому

    Stay Blessed Man. Tnx Alot

  • @Darakon
    @Darakon 2 роки тому +1

    Very cool! Thanks.

  • @KhaledBis-q4e
    @KhaledBis-q4e 5 місяців тому

    HTML for iPhone possible 14:39

  • @shahedhamami8739
    @shahedhamami8739 Рік тому

    Why the sending message function dose'nt work plzz what can i do ?

  • @TecheNology
    @TecheNology Рік тому +1

    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...

    • @shameerkashif
      @shameerkashif 6 місяців тому

      same here, i think you have to enable some stings in your wifi router in the server side and make sure to use the device which is running the server has its ip address

  • @cax4
    @cax4 Рік тому

    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 Рік тому +1

      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.

  • @gulbaharoctonet2946
    @gulbaharoctonet2946 2 місяці тому

    thank u so much u are the best
    Thanks)))

  • @tcgvsocg1458
    @tcgvsocg1458 2 роки тому +1

    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?

  • @noahlantz9938
    @noahlantz9938 Рік тому

    awesome video

  • @caionggabriel607
    @caionggabriel607 Рік тому

    How connect with other rede?

  • @vidya-laxmi
    @vidya-laxmi 2 роки тому

    Cool !

  • @vedkhetle7318
    @vedkhetle7318 Рік тому

    how can i do MITM in this?

  • @SheetalIB
    @SheetalIB 10 місяців тому

    where can i get source code

  • @15.AAYUSHI-lm3su
    @15.AAYUSHI-lm3su Рік тому

    thankyou sir

  • @Toxtroll
    @Toxtroll Рік тому

    source code????

    • @TheRealZitroX
      @TheRealZitroX 6 місяців тому

      It’s like three lines of code. Just type it

  • @kadaliakshay6770
    @kadaliakshay6770 2 роки тому +5

    REQUEST!!!!: Can u pleaseeeeeeeeeeeeeeeeeee give me the code

  • @Joseph-ws5de
    @Joseph-ws5de 2 роки тому +1

    Were is the source code ?

  • @myt436
    @myt436 Рік тому

    Everything you claim is true, the chat is encrypted. It's a shame it's not also secure. :(

  • @JNET_Reloaded
    @JNET_Reloaded 2 роки тому +4

    wheres the github for this please i wana test it out?