Tag Archives: pad block corrupted

Wechat applet decrypts encrypteddata error: pad block corrupted solution

Knowledge map advanced must read: read how large-scale map data efficient storage and retrieval>>>

Today, I encountered an exception when developing a small program to obtain the mobile phone number bound to wechat: javax. Crypto. Badpaddingexception: pad block corrupted

After tossing about for a long time, I suddenly thought of it because:

First, get the encrypted data of mobile phone number through getphonenumber

Then call Wx. Login to get the code

Then get the user’s session by code_ key 。

Finally, use session_ Key, the encrypted data of the mobile phone number and vector decryption to obtain the mobile phone number

The correct approach should be as follows:

Get the code by calling wx.login first

Then get the user’s session through the code_ key 。

Then get the encrypted data of mobile phone number through getphonenumber

Finally, use session_ Key, the encrypted data of the mobile phone number and vector decryption to obtain the mobile phone number

After the reform, there was no problem


This is due to the session obtained by code after calling Wx. Login_ Key is a new session_ key.

Therefore, the encrypted data obtained before calling Wx. Login is not a new session_ Key encrypted data

The encrypted data obtained after calling Wx. Login is the new session_ Key encrypted data