Coding Encrypted Chat in Python

Поделиться
HTML-код
  • Опубликовано: 30 ноя 2024

Комментарии • 50

  • @adarsham4333
    @adarsham4333 Год назад +5

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

  • @allenseay2036
    @allenseay2036 2 года назад +2

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

  • @shubham8192
    @shubham8192 Год назад +2

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

  • @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 Год назад

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

    • @originalbinaryhustler3876
      @originalbinaryhustler3876 11 месяцев назад

      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 11 месяцев назад

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

  • @artaxerxes360
    @artaxerxes360 Год назад +1

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

  • @Minussa9527
    @Minussa9527 9 месяцев назад +1

    exactly what i was looking, keep the good work.

  • @paulthomas1052
    @paulthomas1052 2 года назад +5

    Great explanation and practical code. Thanks :)

  • @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?

  • @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!

  • @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 10 месяцев назад

      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.

  • @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

  • @paulinobrito9161
    @paulinobrito9161 9 месяцев назад

    very good explanation, thanks

  • @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 4 месяца назад

      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

  • @AndersonVanin-i9e
    @AndersonVanin-i9e Год назад +1

    Great tutorial! Congrats

  • @punchcake4832
    @punchcake4832 2 года назад +1

    the matlab joke made me crack lmao

  • @zabij_s
    @zabij_s 10 месяцев назад

    love it! great explanation man

  • @Solexdballer
    @Solexdballer 2 года назад

    Stay Blessed Man. Tnx Alot

  • @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 10 месяцев назад +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.

  • @KhaledBis-q4e
    @KhaledBis-q4e 3 месяца назад

    HTML for iPhone possible 14:39

  • @tiwaztyr4324
    @tiwaztyr4324 2 года назад +2

    Thank you for all the valuable content!

  • @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?

  • @Darakon
    @Darakon 2 года назад +1

    Very cool! Thanks.

  • @caionggabriel607
    @caionggabriel607 Год назад

    How connect with other rede?

  • @vedkhetle7318
    @vedkhetle7318 Год назад

    how can i do MITM in this?

  • @SheetalIB
    @SheetalIB 9 месяцев назад

    where can i get source code

  • @gulbaharoctonet2946
    @gulbaharoctonet2946 9 дней назад

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

  • @15.AAYUSHI-lm3su
    @15.AAYUSHI-lm3su Год назад

    thankyou sir

  • @kadaliakshay6770
    @kadaliakshay6770 2 года назад +5

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

  • @noahlantz9938
    @noahlantz9938 Год назад

    awesome video

  • @myt436
    @myt436 Год назад

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

  • @Toxtroll
    @Toxtroll Год назад

    source code????

    • @TheRealZitroX
      @TheRealZitroX 4 месяца назад

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

  • @Joseph-ws5de
    @Joseph-ws5de 2 года назад +1

    Were is the source code ?

  • @vidya-laxmi
    @vidya-laxmi 2 года назад

    Cool !

  • @JNET_Reloaded
    @JNET_Reloaded 2 года назад +4

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