Base64 encoded data maximum size

后端 未结 4 1978
不思量自难忘°
不思量自难忘° 2021-02-09 11:51

I have a security mechanism that implements symmetric algorithm RijndaelManaged. I managed to find information what is the maximum size of encrypted data using

4条回答
  •  终归单人心
    2021-02-09 12:19

    If you need to check this programatically, you can do so by checking the modulus. Here's some psudocode (no particular language) :

    function base64Inflation (numBytes)
        minimumBase64Bytes = roundDown(numBytes / 3 * 4)    
        modulus = numberOfBytes % 3             // Assuming % is the modulo operator
        if modulus == 0 
            return minimumBase64Bytes           // Exact fit! No padding required.
        else
            return minimumBase64Bytes + 4       // Doesn't quite fit. We need to pad.
    

    I've also implemented the same logic in golang:

    http://play.golang.org/p/JK9XPAle5_

提交回复
热议问题