Quick-x Data Encryption
I. Data Encryption
As long as quick encapsulation is used
Local crypto = require ("framework. crypto") -- algorithm encryption and decryption
To make
Function crypto. encryptxxtea (plaintext, key)
Plaintext = tostring (plaintext)
Key = tostring (key)
Return cccrypto: encryptxxtea (plaintext, String. Len (plaintext), key, String. Len (key ))
End
This is something in the framework. If you are interested, take a look.
Here, my encrypted data is decrypted, read, and encrypted, and saved only when modified, so that the encryption field cannot be changed for the Ghost artifact and so on.
Local key_coin = "coin"
Local encodecoin = crypto. encryptxxtea (0, key_coin) -- gold coins
-- Gold coin ----------
Local writecoin = function ()
Userdefault: setstringforkey (key_coin, encodecoin)
End
Function gamedata: getcoin ()
Return tonumber (crypto. decryptxxtea (encodecoin, key_coin ))
End
Function gamedata: setcoin (value)
Local coin = self: getcoin () + Value
If coin <0 then returnend
Encodecoin = crypto. encryptxxtea (coin, key_coin)
Writefuncs [key_coin] = writecoin
Eventmanager: dispatchevent ({name = event_data, kind = player. coin, value = coin })
Return coin
End
I haven't written a blog for a long time. I 've written some bad stuff before. Sorry. This time I will introduce some new features of quick-x quick-cocos2d-x.