Java RSA Encryption

后端 未结 3 1777
灰色年华
灰色年华 2021-02-04 13:42

I am trying to encode a simple String \"test\" back and forth.

public static String encode(Key publicKey, String data) throws NoSuchAlgorithmException, NoSuchPad         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 14:26

    If you have a long data, you should either split it to data chunks that fits and encrypt / decrypt each of them (not such a good idea) or encrypt / decrypt them using a symmetric algorithm (AES / DES / RC4 / etc.), encrypt the symmetric key with the RSA public key and send both to the other side. (much better idea).

    The second approach is a very common approach, since asymmetric encryption algorithms are much more expensive than symmetric algorithms (for both encryption and decryption).

提交回复
热议问题