RSA and Base64 encoding too many bytes

后端 未结 1 1064
南旧
南旧 2021-02-11 03:54

I am trying to implement RSA encryption with Base64 encoding. The sequence is:

String -> RSA encrypt -> Base64 encoder -> network -> Base64 decoder*          


        
相关标签:
1条回答
  • 2021-02-11 04:29

    There is something wrong with your encoding. Using base 64 instead of base 256 means an increase of 8-bit/6-bits required or 1/3 similarly decoding results in a drop of 1/4 e.g. 1248 * 6 / 8 = 936

    The problem appears to be that you are converting 8-bit data into 16-bit string before encoding. This requires 512 * 16 / 6 bytes = ~1365.

    You need a Base64 stream which takes bytes instead of chars/Strings.

    Perhaps using Base64.encode() is what you need?

    0 讨论(0)
提交回复
热议问题