Help with cipher

I have a strange bug that I can’t seem to fix. And I was hoping someone could point me in the right direction.

In my games I encrypt my save files to provide some kind of security. But on a few device (I haven’t been able to reproduce the problem) the decryption fails. On most devices the encryption/decryption works flawlessly.

Basically what I do is write the contents of a dictionary to string. I then send that string to be encrypted and saved to a file. That is setup to be cross platform, but the Android code which fails from time to time looks like this:

@
void PlatformToolbox::saveAndEncryptStringToFile(std::string string, const char fileName, const charfilePath)
{
JniMethodInfo t;
jstring ret;

std::string path2 = “”;
path2.append(filePath);
path2.append(fileName);
const char *path = path2.c_str();

if (JniHelper::getStaticMethodInfo(t, jniCipher
,“saveAndEncryptStringToFile”
,“(Ljava/lang/String;Ljava/lang/String;)V”))
{
jstring StringArg1 = t.env~~>NewStringUTF);
jstring StringArg2 = t.env~~>NewStringUTF(path);
t.env~~>CallStaticVoidMethod;
}
}
std::string PlatformToolbox::loadAndDecryptFileToString
{
JniMethodInfo t;
jstring ret;
std::string path2 = “”;
path2.append;
path2.append;
const char *path = path2.c_str;
if Ljava/lang/String;"))
{
jstring StringArg1 = t.env~~>NewStringUTF(path);
ret = (jstring)t.env~~>CallStaticObjectMethod;
return t.env~~>GetStringUTFChars(ret,false);
}
}
@

The cipher code can be found here: https://dl.dropbox.com/u/7279678/SimpleCrypto.java

Any help would be much appreciated, not sure where I might be doing something wrong.

Also I was getting these errors from the Google Play developer console:

@
java.io.IOException: pad block corrupted
at javax.crypto.CipherInputStream.read(CipherInputStream.java:100)
at javax.crypto.CipherInputStream.read(CipherInputStream.java:155)
at javax.crypto.CipherInputStream.read(CipherInputStream.java:123)
@

1 Like