Java RSA Encryption

后端 未结 3 1793
灰色年华
灰色年华 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:22

    From here:

    The RSA algorithm can only encrypt data that has a maximum byte length of the RSA key length in bits divided with eight minus eleven padding bytes, i.e. number of maximum bytes = key length in bits / 8 - 11. If you want to encrypt larger data, then use a larger key, for example, a key with 4096 bits will allow you to encrypt 501 bytes of data.

提交回复
热议问题