Crypto and saving errors

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
MSAdmin
Posts: 5
Joined: Thu Apr 28, 2016 5:19 pm

Crypto and saving errors

Post by MSAdmin »

So far I have been using ES with ease as a key/value solution, but now I have run into 2 issues.

1) I changed the encryption key ( assuming it was the same for all installs ) and now I am getting "Bad PKCS7 padding. Invalid length 0." error. The key I used was the same number of characters and using no special characters. Do I have to reimport the asset?

2) The next error is: "The data, tag, file or folder you are looking for does not exist. Please ensure that ES2.Exists(string identifier) returns true before calling this method."

The code below is attached to 3 different buttons. The first 2 buttons throw the error and the third is successfully saved. It should have an entry for all three buttons if I understand it correctly.

Code: Select all

public Button upgradeButton;

...

void Start () {
		if (ES2.Exists("GameData.dat") == true) {
			crystalCount = ES2.Load<int>("GameData.dat?tag=CrystalCount");
			upgradeLevel = ES2.Load<int>("GameData.dat?tag="+ upgradeButton.name);
		} else {
			ES2.Save<int>(0, "GameData.dat?tag=CrystalCount");
			ES2.Save<int>(0, "GameData.dat?tag="+ upgradeButton.name);
		}
	}

...
I have used this similar code in a different script and those buttons have been saved fine.

Does anyone have any insight as to what may be going on here? Any insight would be helpful.

Thanks for your time and attention.

User avatar
Joel
Moodkie Staff
Posts: 3676
Joined: Wed Nov 07, 2012 10:32 pm

Re: Crypto and saving errors

Post by Joel »

Hi there,

The 'Bad Padding' error is usually thrown when a wrong password is given. Is this error happening at the same time as the not exists exception, and if so, which order do they happen? Also would you be able to let me know on which line of your code these errors occur?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started

MSAdmin
Posts: 5
Joined: Thu Apr 28, 2016 5:19 pm

Re: Crypto and saving errors

Post by MSAdmin »

The bad padding error goes away if I disable encryption and it independent of the other error.

I attached a screenshot.

The Unity console says:

Easy Save 2 Error: The data, tag, file or folder you are looking for does not exist. Please ensure that ES2.Exists(string identifier) returns true before calling this method.
UnityEngine.Debug:LogError(Object)
ES2Reader:ProcessHeader(Key, ES2Type, ES2Type, String)
ES2Reader:Read(String)
ES2:Load(String)
Upgrades:Awake() (at Assets/Scripts/Upgrades.cs:39)

Easy Save 2 Error: The data, tag, file or folder you are looking for does not exist. Please ensure that ES2.Exists(string identifier) returns true before calling this method.
UnityEngine.Debug:LogError(Object)
ES2Reader:ProcessHeader(Key, ES2Type, ES2Type, String)
ES2Reader:Read(String)
ES2:Load(String)
Upgrades:Awake() (at Assets/Scripts/Upgrades.cs:40)
Attachments
Code Snippet
Code Snippet
Capture.PNG (23.62 KiB) Viewed 18863 times

User avatar
Joel
Moodkie Staff
Posts: 3676
Joined: Wed Nov 07, 2012 10:32 pm

Re: Crypto and saving errors

Post by Joel »

Hi there,

It sounds like the encryption error is being caused because you're trying to load unencrypted data when encryption is enabled. Usually the easiest way to test this is to delete all of your existing save data, enable encryption and try saving from scratch.

The missing tag error can only occur in this case if the tag is indeed not in the file. The best thing to do would be to Debug.Log the name of the tag you're trying to load on line 40, and then view the file using the File Editor (Assets > Easy Save 2 > File Editor) and check to see if that tag is in the file.

If the tag is indeed in the file, could you create a basic project which replicates the error, upload it to something like WeTransfer and PM me the link? Hopefully then I'll be able to replicate the error.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started

MSAdmin
Posts: 5
Joined: Thu Apr 28, 2016 5:19 pm

Re: Crypto and saving errors

Post by MSAdmin »

I was under the assumption that all I had to check for was the base file. I have adjusted the if statement to this and everything is working. Thanks!

Code: Select all

		if (ES2.Exists("GameData.dat?tag=CrystalCount") == false) {
			ES2.Save<int>(0, "GameData.dat?tag=CrystalCount");
		} else {
			crystalCount = ES2.Load<int>("GameData.dat?tag=CrystalCount");
		}

		if (ES2.Exists("GameData.dat?tag="+ upgradeButton.name) == false) {
			ES2.Save<int>(0, "GameData.dat?tag="+ upgradeButton.name);
		} else {
			upgradeLevel = ES2.Load<int>("GameData.dat?tag="+ upgradeButton.name);
		}
Lastly, what would be the recommended way to establish a base file with all the necessary tags on the first run of the game?

User avatar
Joel
Moodkie Staff
Posts: 3676
Joined: Wed Nov 07, 2012 10:32 pm

Re: Crypto and saving errors

Post by Joel »

Great to hear that solved your problem!

Generally the best way to create a base save file is to save it to Resources (see http://docs.moodkie.com/easy-save-2/gui ... resources/) in the Editor so it gets included with your build. Then if the file doesn't exist when you try to load it in your code, load the version from Resources and save it to the default save location (using ES2.LoadRaw and ES2.SaveRaw).

Hope this makes sense!

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started

MSAdmin
Posts: 5
Joined: Thu Apr 28, 2016 5:19 pm

Re: Crypto and saving errors

Post by MSAdmin »

That makes very little sense to me but that may be due to being novice at Unity (and development in general). Is there a tutorial and sample code for that implementation?

User avatar
Joel
Moodkie Staff
Posts: 3676
Joined: Wed Nov 07, 2012 10:32 pm

Re: Crypto and saving errors

Post by Joel »

Hi there,

As a novice, an easier way might be to create the file yourself using a series of ES2.Save calls if the file doesn't exist. There are a few pitfalls when using Resources which this method would avoid.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started

MSAdmin
Posts: 5
Joined: Thu Apr 28, 2016 5:19 pm

Re: Crypto and saving errors

Post by MSAdmin »

That is how I have been doing it so far. I will continue as to do so. Thanks again.

Locked