I recently had to do something similar, and it was not easy. But I managed to do it. Possible obfuscation and / or encryption scenarios. The question is, do you have time to devote to this? You need to make sure that any obfuscation / encryption method you use is very complicated and time consuming to crack and that it does not slow down the execution time of the script.
If you want to quickly encrypt Rscript code, you can do this using this site .
I tested the following rcode using the above site, and it produced a very intimidating output that somehow worked:
#!/usr/bin/env Rscript for (i in 1:100){ if (i%%3==0) if (i%%5==0) print("fizzbuzz") else print("fizz") else if (i%%5==0) print("buzz") else print(i) }
If you have some time on your hands and you want to encrypt your script yourself using your own impromptu method, you will want to use the openssl command. What for? Because this is apparently one encryption tool that is available on most, if not all Unix systems. I tested it on Linux (ubuntu, centos, redhat, mac) and AIX.
The easiest way to use Openssl to encrypt a file or script:
1. cat <your-script> | openssl aes-128-cbc -a -salt -k "specify-a-password" > yourscript.enc OR 2. openssl aes-128-cbc -a -salt -in <path-to-your-script> -k "yourpassword"
To decrypt a script using Openssl (note the "-d"):
1. cat yourscript.enc | openssl aes-128-cbc -a -d -salt -k "specify-a-password" > yourscript.dec OR 2. openssl aes-128-cbc -a -d -salt -in <path-to-your-script> -k "yourpassword" > yourscript.dec
The trick here would be to automate the password, so your users do not need to provide a password every time they want to run a script. Or maybe what you want?
RoyMWell
source share