Java public key exchange through a trusted server

I wanted to create a relay server to which you can safely transfer messages between two peers (for the purpose of nat bypass) for P2P communication. In particular, I referred to the steps in the diagram in this document for exchanging private keys .....

in particular, he says "public key A is encoded with public key B" and vice versa. However, I came across a problem: when I use both keys for 1024 bits, I really got an illegalblocksizeexception when I try to use the public key to encode another.

Reading other questions, some answered that there is a limit on the size of the data that the public can encrypt using RSA. Can I find out if there are any details that I can miss that are omitted from the diagram, or am I doing the wrong thing trying to exchange keys as such ...

+4
source share
1 answer

RSA public keys cannot encrypt data whose length exceeds the bit length of their module. Therefore, a 1024-bit RSA public key can only encrypt up to 1024 bits of data. A 1024-bit public key file will be larger than 1024 bits because the module is only part of the shared data. Therefore, a 1024-bit RSA public key cannot encrypt another RSA 1024-bit public key.

More importantly : you should not encrypt the public key with anything. Public keys are simple: public; there is no need for privacy when it comes to their contents. If you want to β€œbless” the public key as appropriate for a specific purpose, then sign it using a private key that has some meaning. Or better yet, issue a certificate for the public key from a certification authority that is trusted by all participants in your protocol.

+1
source

Source: https://habr.com/ru/post/1432022/


All Articles