r/javahelp • u/Lactios • Jan 20 '20
Encrypting messages between clients
So we have an assignment in which we have to create 5 clients that can be messaging each other, through the same port and using an interface, the only thing we can't get right, is the encryption part of the assignment. So, the messages need to be encrypted and decrypted after and before sending and recieving them. How can we do this? Any idea?
2
u/nerdyhandle Jan 20 '20
Find an encryption algorithm that will suit your needs. Have each client encrypt before send then have the receiving client decrypt on receive.
For the class I assume it would be sufficient to use a hard coded decryption key in the code. Although in real world applications you wouldn't do this but it should still get the primary functionality across.
1
u/AryanPandey Jan 21 '20 edited Jan 21 '20
I love to have this part of the project. You can go for Java inbuilt cryptography. (There are not great, but I used it , as I don't want any external dependencies)
These library are somewhat necessary javax.crypto.* And java.util.Base64;
NOTE: For valid reasons Except RSA and AES ,all other algorithms are now Broken form this library, means they can be decrypted!
So USE only RSA and AES for quality project.
As I am not a cryptographer , I cannot help that much , I have used only the library. I can give you some practical experience. Get understanding of Base64 conversions, before getting hands on library.
I would say YOUR implementation of the library is MUST need for making it not decrypt-able easily. Otherwise, Even you choose the right library, and that could also is not matching your goals.
For precision there must be some guys trying to break your code, so that you can know what's best practices.
For some good pages I landed on web , before starting a similar project are
Don't just copy Examples as I feel they are not that great, just try to understand from them.
Except this First one. (As I loved this blog.) https://www.veracode.com/blog/research/encryption-and-decryption-java-cryptography
https://www.tutorialspoint.com/java_cryptography/java_cryptography_encrypting_data.htm
https://www.novixys.com/blog/java-aes-example/
Anything I missed, or you wanted, please comment, I will try my best to answer, if I know about that.
0
u/gregorydgraham Jan 20 '20
A term you might want to search for is “bcrypt”
4
u/nutrecht Lead Software Engineer / EU / 20+ YXP Jan 21 '20
Which is a password hash and not at all what the OP needs.
2
3
u/snot3353 COMPUTERS!!! Jan 20 '20
Look up Java cryptography. There are a lot of libraries that will do this sort of thing for you.