Forum: JRuby Source Code Encryption

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Kengsreng T. (Guest)
on 2015-05-05 10:13
How to encrypt source code deployed on Apache Tomcat?

I using rails on jruby deployed on client machine, and I want to prevent
client from hacking my source code.

Any ideas?

Karol B. (Guest)
on 2015-05-05 11:36
(Received via mailing list)
Chances are you're already using Warbler to generate a .war ... just try
it's compiled feature.

It will pre-compile all .rb files into -> .class ones and replace .rb
file's content to load the compiled .class.

If you're really into it you can further obfuscate with tools such as
Proguard, although I would be a little cautious there.

Kengsreng T. (Guest)
on 2015-05-08 02:29

Do you know how to compile xxx.yml files ?
Doug Hathaway (Guest)
on 2015-05-08 02:49
(Received via mailing list)
You could perhaps encrypt the contents of the YML file, then decrypt
before parsing.

Sent from Mailbox

On Thu, May 7, 2015 at 6:29 PM, Kengsreng T. 
Christian MICHON (Guest)
on 2015-05-09 11:46
(Received via mailing list)
Use jrubyc to compile your main ruby script to class files. That should
Keith B. (Guest)
on 2015-05-09 23:19
(Received via mailing list)
Even with compiling, the resulting class files can be inspected
(somewhat) with javap.

If you run javap -v on the file (don’t included the .class extension)
then you can see the method signatures and Java byte code instructions.
Not at all like seeing the original source, but not at all encrypted

- Keith
Christian MICHON (Guest)
on 2015-05-09 23:50
(Received via mailing list)
I agree but there's no way to really recover the original ruby script.
best you'll retrieve what you listed and the string constants.

It's the easiest form of obfuscation I know for jruby.

If you have another suggestion, I will test it
Christian MICHON (Guest)
on 2015-05-09 23:52
(Received via mailing list)
I almost forgot... Have a look at jd-gui if you're using Windows. You'll
get a much better java decompilation than what you suggested.
On May 9, 2015 9:49 PM, "Christian MICHON" 
Kengsreng T. (Guest)
on 2015-05-11 09:58
Hi Christian,

Is Jrubyc can compile yaml file?
Christian MICHON (Guest)
on 2015-05-11 14:37
(Received via mailing list)
No jrubyc will only compile ruby files, ie .rb files.

If you wish to preserve the yaml content, I would suggest to simply
it with ruby-rc4 (why not?) and obfuscate the string used as key through
dictionary. That would do.

So in total:
- compile all rb files into class files using jrubyc
- encrypt yaml and xml with ruby-rc4, and obfuscate the key within a

If you need more dedicated help, just point me to a git repository. ;-)

On Mon, May 11, 2015 at 7:58 AM, Kengsreng T. 
Tim U. (Guest)
on 2015-05-11 20:05
(Received via mailing list)
Why don't you just put your settings in a .rb file?

On Mon, May 11, 2015 at 10:36 PM, Christian MICHON <
Christian MICHON (Guest)
on 2015-05-12 00:47
(Received via mailing list)
I'm not the creator of this thread, but I believe settings should be
of a configuration file instead of being in the code itself.

Database.yaml in rails is a typical example of such approach.
christian (Guest)
on 2015-05-13 00:30
(Received via mailing list)
I followed the thread and realized the you want to "encrypt" some
or something when you asked about yaml file.

if you use something like configurator gem to replace yaml with ruby
then the jrubyc will still keep yaml values as literals inside the class
files. even you decide to use some encryption for the yaml file you will
face the same problem that the encryption key which is just a literal or
byte array inside a class file. all you gain is that nobody tumbles over
the "password" accidentally but anyone who wants to unwrap if can do so
it might take only a few minutes to do so.

if your intention is to obfuscate your ruby codebase then jrubyc could
OK but even this can be reversed. but is probably not feasible for
codebase as it is manual procedure.

I personally find it important to think on how to undo the protection
put in place - just to get a feeling how good your protection is.

- christian
This topic is locked and can not be replied to.