Custom class array and CryptographicException

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
BFRETHGIL
Posts: 23
Joined: Wed Jun 13, 2018 8:25 pm

Custom class array and CryptographicException

Post by BFRETHGIL »

Hey there,

I started to use ES2Writer and ES2Reader, and I have two issues and 1 question:

1. I have a simple Level class-

Code: Select all

[Serializable]
public class Level 
{
   public string levelName;
   public int target, scores;
   bool unlocked;
}
I have 100 levels which I store in an array (Level[] levelsArray), I want to save this array to my file
I know that I can write int[] but what about a custom class like my Level class? Is it a type I can add?
I basically need to be able to do- reader.ReadArray<Level>("levelArrayTag");
What's the best way to save it together with my other keys in that file?

2. I keep getting this error- CryptographicException: Invalid input block size.
Mono.Security.Cryptography.SymmetricTransform.FinalDecrypt (System.Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/Mono.Security.Cryptography/SymmetricTransform.cs:462)..............

I removed the data files, but I'm still getting the same error
I enabled the password through the editor (ES2). Not sure why it keeps happening.

3. Regarding ES2Writer, and it might be a stupid question but I want to make sure-
you commented that "you should not open multiple ES2Readers or ES2Writers for the same file"
Do I need to create 1 global writer/reader, and all other classes should use the same one I created? Something like-

Code: Select all

using(OtherClass.instance.reader = ES2Reader.Create("myFile.txt"))
{
...
}
Or is ok to use it multiple times as long as I don't open it twice at the same time?

Thanks! I'm getting there......
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Custom class array and CryptographicException

Post by Joel »

Hi there,

A cryptographic exception in an ES3Writer usually suggests that you're not reading in the same order as you wrote the data to your file. You can usually test whether this is the case by deleting the save file, disabling encryption, and then see if an exception is still thrown when you write and read.

You can find information on adding support for other types in Easy Save 2 in the Adding Support for Other Types guide here:
https://docs.moodkie.com/easy-save-2/gu ... her-types/

With regards to ES2Readers and ES2Writers, it's okay to use them multiple times as long as you don't open it twice at the same time. So for example, you shouldn't open two writers on the same file, or open a reader on a file when there is a writer already open for that file (or vice versa).

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
BFRETHGIL
Posts: 23
Joined: Wed Jun 13, 2018 8:25 pm

Re: Custom class array and CryptographicException

Post by BFRETHGIL »

I use the ES2 editor for encryption and ES2Writer (not es3)
When I disable encryption I don't get any error/exception
I also don't need to read my tags in order because I read the values by given tags (every time I need a different tag, and I don't use it Sequentially).

I tried to remove the files multiple times and play with it but I'm still getting CryptographicException whenever I enable "Encrypt Data" on the ES2EDITOR
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Custom class array and CryptographicException

Post by Joel »

Apologies, in my previous message I meant ES2Writer, not ES3Writer.

That's very strange. Please could you PM me a project and instructions to replicate this, as I don't appear to be able to replicate it at my end, and I've had no other reports of this?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
BFRETHGIL
Posts: 23
Joined: Wed Jun 13, 2018 8:25 pm

Re: Custom class array and CryptographicException

Post by BFRETHGIL »

There is nothing to replicate, I get this error before my scripts are even loaded- It's the first line I get on debug.log
CryptographicException: Invalid input block size.
Mono.Security.Cryptography.SymmetricTransform.FinalDecrypt (System.Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/Mono.Security.Cryptography/SymmetricTransform.cs:462)
Mono.Security.Cryptography.SymmetricTransform.TransformFinalBlock (System.Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/Mono.Security.Cryptography/SymmetricTransform.cs:554)
System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock (System.Byte[] inputBuffer, Int32 in

It happens only when I enable encryption on the editor
the solution is to uncheck Encrypt Data on ES2EDITOR and return to play mode (no need to remove files)

Unity 2017.3.0p4
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Custom class array and CryptographicException

Post by Joel »

Hi there,

I am not getting this at my end, and I've had no other reports of this, so unfortunately I will need to see your project so I can work out why this is going on.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
BFRETHGIL
Posts: 23
Joined: Wed Jun 13, 2018 8:25 pm

Re: Custom class array and CryptographicException

Post by BFRETHGIL »

No Problem I'm sending you a new project file to your email now.

Notes- I found out that this problem occurs only on 1 specific scene,
I opened a new project, copied that problematic scene there, removed all gameobjects from the scene, removed the saved ES2 files, and I can still see the problem
So now you are going to have these files. A new project, an empty scene, and 1 error.
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Custom class array and CryptographicException

Post by Joel »

Hi there,

It looks like ES2AutoSave was enabled in your scene, which was conflicting with the default settings.

If you go to Window > Easy Save 2 > Auto Save > Settings and press Remove Auto Save from Scene, this should fix your issue.

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