且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在iOS设备上本地保存游戏得分...需要安全吗?

更新时间:2022-10-18 10:41:42

我实际上会这样做:

NSDictionary 中,并将其转换为 NSData 对象。现在来了一个很酷的部分:

使用这个类将它加密成AES:


https:// web。 archive.org/web/20160806074714/http://iphonedevelopment.blogspot.com/2009/02/strong-encryption-for-cocoa-cocoa-touch.html



这是一个军事标准加密,它将返回一个加密的 NSData 对象。然后只要将它保存到文件并在必要时读/写。我对这个课程有着非常好的经验,用户也无法做任何事情。



比使用 NSUserDefaults 。



试试吧!

Do I need to store the score with a hash, ie to protect it from being edited/cheated by a user? From my newb knowledge, the user is unable to view and manipulate this locally stored data, as plist files for example. Can anyone elaborate?

[Edit] I'm storing scores locally and periodically uploading them to Game Center leaderboards. Even if the device is jailbroken I'd like to have security to prevent scores being manipulated by the user. What is a good approach?

I actually would do this:

Save it in an NSDictionary and convert it to an NSData object. Now comes the cool part:

Encrypt it into AES using this class:
https://web.archive.org/web/20160806074714/http://iphonedevelopment.blogspot.com/2009/02/strong-encryption-for-cocoa-cocoa-touch.html

This is a military standard encryption which will return an encrypted NSData object. Then just save it to file and read/write whenever necessary. I've had really good experiences with this class and the user can't do anything to it.

Much better than just storing it in plain sight using NSUserDefaults.

Give it a go!