Creating an encrypted save file - ruby

I'm trying to make a game in Ruby, and my latest addition is to save files, however, I'm having a major problem with encrypting them.
I already got the saving and loading methods set up, but I don't want to save them in plain-text, because that's begging for cheating. No matter what, the methods I use to try and store them encrypted, compressed, etc., all seem to spring some error on me.
What's the best method for saving text in a file? The only important thing is that the file can't be opened and edited.

You can use crypt gem to encrypt/decrypt your file.
But keep in mind that if your users can view your Ruby script, there's basically no way to hide your data, since any encryptions requires some kind of keys.

Related

Laravel encrypter sometimes does not work

I had a fully functional encrypt/decrypt method set with Laravel, I tested it properly and was working fine.
The other day I received an error saying The Payload is Invalid and started debugging: looks like the function is not working. So I tested again but it works fine if I'm the one creating the encrypted records, which doesn't make sense because it should either work or fail every single time. Again, the method is a simple encrypt/decrypt of a column named password in the database on a table named servers.
Any idea what the problem may be? Is it possible that Laravel encrypts for a specific user? If so, how can I encrypt for multiple users?
I found a solution changing the encryption mechanism from
encrypt() -> decrypt()
to
Crypt::encryptString() -> Crypt::decryptString()
If anybody has an explanation why the second method works where the first doesn't, feel free to expand and you'll have my upvote

Is it possible to save and retrieve a Gesture using SharedPreferences?

/res/raw doesn't appear to be an option and saving to SD is fine but i'd prefer to avoid that dependency
Investigating this SharedPrefs appears to be impossible and a bad idea. GestureLibrary.fromPrivateFile() does the job saving the file privately off SD.

Output all language strings in Revel?

I'm developing an API Server in Go and the server (at the moment) handles all translations for clients. When an API client fetches particular data it also asks for the translations that are available for the given section.
Ideally I want to have the following folder structure:
/messages
/home.en
/home.fr
/home.sv
/news.en
/news.fr
/news.sv
Where news and home are distinct modules.
Now the question I have for Revel is is it possible to fetch ALL language strings for a given module and given locale? For example pull all home strings for en-US.
EDIT:
I would like the output (something I can return to the client) a key:value string of translations.
Any guidance would be appreciated.
It seems to me that revel uses messaged based translation (just like gettext does), so you need
the original string to get the translation. These strings are stored in Config objects,
which are themselves stored in messages of i18n.go, sorted by language.
As you can see, this mapping is not exported, so you can't access it. The best way
to fix this is to write a function for what you want (getting the config by supplying a language)
or exporting one of the existing functions and create a pull request for revel.
You may workaround this by copying the code of loadMessageFile or by forking your version
of revel and exporting loadMessageFile or parseMessagesFile. This also is a great opportunity
to create a pull request.
Note that the localizations are stored in a INI file format parsed by robfig/config,
so manually parsing is also an option (although not recommended).

How can I work with Windows security groups without knowing their localized names in advance?

I've searched around online but can't find what I'm after. Basically, during an install, we fire off a separate executable that basically brute forces a few folders to be read/write enabled for the user group "EVERYONE".
Now, the person that wrote this never took into consideration system language. I had a call with a customer in France that kept failing installation because "EVERYONE" isn't what we would expect.
I'm after an API call to Windows that would return a security group name which would be "safe" to use in a localized environment. Essentially I'm looking to safely edit this code so instead of hardcoding in "EVERYONE", we call a function instead.
The fundamental mistake here is not so much the use of EVERYONE, but rather that the code is using names at all. Instead of using names you should use the well-known SIDs. In your case you need S-1-1-0.

Serving Files in Zend Framework MVC

What is the best practice when serving files from the Zend Framework MVC? These files have to be served from the MVC as they are protected.
I know you can read in the file and place it into the Response object but this seems like a bad practice as you would be reading the entire file into memory then serving it. Right now I usually do:
header('Content-type: image/jpeg');
fpassthru(fopen($path, 'rb'));
exit;
But this also doesn't seem right as I'm stopping the execution of the script. Any suggestions?
I see nothing wrong with just exit(); What you will need to be careful of is any output buffering layers you may have on (gzip compression, etc). Large files could blow up those buffers pretty quick, so you'll want to close them out and potentially 'chunk' your output with a fopen/fread loop.
I would suggest building a super-simple script for retrieving files based on ticket system like in CMS you generate ticket to DB - filename, unique-hash and than redirect to the super-simple file-retieving script (file.php?hash=asd52ad3as1g5). It will get the hash from query and based on it fetch the real filename and push that to output as you have written using fpassthru. The hash need to be unique and hard to guess...
You could try using the X-Sendfile header. It is supported by lighttpd and newer versions of apache. Basically the webserver will replace the output of the script with the file you specified. The downside being that it is specific to the configuration of the webserver, so you may be on a host that doesn't support it.

Resources