Bad PKCS7 padding. Invalid length 0.

Discussion and help for Easy Save 3
Post Reply
pita0017
Posts: 2
Joined: Mon Apr 29, 2019 6:12 pm

Bad PKCS7 padding. Invalid length 0.

Post by pita0017 »

Hello,

I'm getting the following errors as soon as the scene loads. Tried clearing the persistent data path already. My settings are: File/Persistent Data Path. Any ideas?

Code: Select all

CryptographicException: Bad PKCS7 padding. Invalid length 0.
Mono.Security.Cryptography.SymmetricTransform.ThrowBadPaddingException (System.Security.Cryptography.PaddingMode padding, System.Int32 length, System.Int32 position) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
Mono.Security.Cryptography.SymmetricTransform.FinalDecrypt (System.Byte[] inputBuffer, System.Int32 inputOffset, System.Int32 inputCount) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
Mono.Security.Cryptography.SymmetricTransform.TransformFinalBlock (System.Byte[] inputBuffer, System.Int32 inputOffset, System.Int32 inputCount) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
System.Security.Cryptography.CryptoStream.FlushFinalBlock () (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
System.Security.Cryptography.CryptoStream.Dispose (System.Boolean disposing) (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
System.IO.Stream.Close () (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
System.IO.Stream.Dispose () (at <d7ac571ca2d04b2f981d0d886fa067cf>:0)
ES3Internal.AESEncryptionAlgorithm.Decrypt (System.IO.Stream input, System.IO.Stream output, System.String password, System.Int32 bufferSize) (at Assets/Plugins/Easy Save 3/Scripts/ES3Crypto.cs:139)
ES3Internal.UnbufferedCryptoStream..ctor (System.IO.Stream stream, System.Boolean isReadStream, System.String password, System.Int32 bufferSize, ES3Internal.EncryptionAlgorithm alg) (at Assets/Plugins/Easy Save 3/Scripts/ES3Crypto.cs:165)
(wrapper remoting-invoke-with-check) ES3Internal.UnbufferedCryptoStream..ctor(System.IO.Stream,bool,string,int,ES3Internal.EncryptionAlgorithm)
ES3Internal.ES3Stream.CreateStream (ES3Settings settings, ES3Internal.ES3FileMode fileMode) (at Assets/Plugins/Easy Save 3/Scripts/Streams/ES3Stream.cs:62)
ES3Reader.Create (ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:308)
ES3.Load[T] (System.String key, T defaultValue, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:303)
ES3AutoSaveMgr.Load () (at Assets/Plugins/Easy Save 3/Scripts/Auto Save/ES3AutoSaveMgr.cs:42)
ES3AutoSaveMgr.Awake () (at Assets/Plugins/Easy Save 3/Scripts/Auto Save/ES3AutoSaveMgr.cs:56)
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Bad PKCS7 padding. Invalid length 0.

Post by Joel »

Hi there,

This error most commonly occurs because the password you're using to load the data does not match that used to save it, or the data is being loaded with encryption enabled but is not encrypted.

Please could you show me the code you're using to save and load so I can try to understand what is happening?

It could also be that no password has been set. Please could you go to Window > Easy Save 3 > Settings and check that the password isn't blank.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
pita0017
Posts: 2
Joined: Mon Apr 29, 2019 6:12 pm

Re: Bad PKCS7 padding. Invalid length 0.

Post by pita0017 »

Hey Joel,

I updated to the newest version of Easy Save and now get the following errors:

Code: Select all

FormatException: File is not valid JSON. Expected '{' at beginning of file, but found 's'.
ES3Internal.ES3JSONReader..ctor (System.IO.Stream stream, ES3Settings settings, System.Boolean readHeaderAndFooter) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:39)
ES3Reader.Create (ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:314)
ES3.Load[T] (System.String key, T defaultValue, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:306)
ES3.Load[T] (System.String key, T defaultValue) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:278)
Splash.Start () (at Assets/Scripts/Splash.cs:14)
Here's the relevant loading code in Splash.cs:

Code: Select all

int currentUser = ES3.Load<int>("currentUser", 0);
        if (currentUser != 0) {
            SceneManager.LoadScene("01 MainMenu");
        } else {
            SceneManager.LoadScene("00a NewUser");
        }
I have set the encryption and password settings in the Easy Save 3 settings menu and cleared both the persistent data path and player prefs. After clearing I can go through all the scenes in the game and save and load data without issue. Once I press stop and then restart the game is when the errors start up. Also I'm on Unity 2018.4.0f1. If you want any more information from me just let me know.

Thanks for your help.
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Bad PKCS7 padding. Invalid length 0.

Post by Joel »

Hi there,

Please could you PM me a basic project which replicates this with instructions?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Helperrr
Posts: 9
Joined: Fri Mar 15, 2019 4:38 pm

Re: Bad PKCS7 padding. Invalid length 0.

Post by Helperrr »

As an FYI to others, if you have a password set in the AutoSave tab, under Advanced Settings, but you do not have a password or encryption setup in the Settings tab, you will get that error message.

To resolve, make sure encryption and password are the same in both the settings tab and Auto Save tab as joel recommends.
Post Reply