Tag Archives: base64

[Solved] Error “incorrect padding” in decoding of Base64 module in Python

Problem description
decodes the field information encoded by Base64, which is normally decoded in the base64 encoding and decoding tool, but b64decode and A2B in the modules Base64 and binascii under python_ Decoding error in Base64 and other methods
the error information is as follows

---------------------------------------------------------------------------
Error                                     Traceback (most recent call last)
<ipython-input-11-787bc11958b4> in get_proxies(urls)
     14         try:
---> 15             raw = base64.b64decode(response)
     16         except Exception as r:

c:\program files\python3\lib\base64.py in b64decode(s, altchars, validate)
     86         raise binascii.Error('Non-base64 digit found')
---> 87     return binascii.a2b_base64(s)
     88 

Error: Incorrect padding

Solution

Base64 in Python is read in 4, so the field to be decoded should be a multiple of 4, not enough to add ‘=’

# The field a to be decoded is judged, and if it is a multiple of 4, it is unchanged, and if not, how much is missing, how much is made up
a = a + '=' * (4 - len(a) % 4) if len(a) % 4 != 0 else a

[Solved] RSA encryption request error: javax.crypto.badpaddingexception: decryption error

📖 Abstract


Share today — RSA encryption request error: javax. Crypto. Badpaddingexception: decryption error , welcome to pay attention!

Read related articles: spring boot + security based on the separation of the front and back RSA password encryption login process


🌂 resolvent

In the login method, the space can be replaced by a + sign, just ask if you want to be coquettish

String inputDecryptData = "";
        try {
            Object privateKey = redisUtil.get(Constant.RSA_PRIVATE_KEY);

            inputDecryptData =  RSAUtils.decrypt(password.replaceAll(" ","+"), RSAUtils.getPrivateKey(privateKey.toString()));
        } catch (Exception e) {
            log.error("RSA encryption and decryption exceptions occurred ======>", e);
            throw new BizException("RSA encryption and decryption exception occurred");
        }

Finally, thank you for watching patiently, leaving a like collection is your greatest encouragement to me!