Protect / encrypt R-packet code for distribution

I am writing a package in R and would like to protect / glue the code. In principle, when viewing the code of my package, it should be encrypted and not readable. I read that someone had encrypted his code (1), however I no longer found any information about this. I know that I can just write code in C / C ++ and compile it, however I would like to include it in R and just β€œprotect” it there.

My question is: is it possible, how is it possible?

I appreciate your answer!

Reference:

(1) link

+8
r obfuscation
source share
2 answers

Have you tried following this stream?

https://stat.ethz.ch/pipermail/r-help/2011-July/282717.html

At some point, the R code must be processed by the interpreter R. If you give someone an encrypted code, you must provide them with a decryption key so that R can start it. Maybe you can hide the key somewhere and hope that they do not find it. But they must have access to it in order to somehow generate plain text code.

This is true for all programs or files that you run or view on your computer. Encrypted PDF Files? No, they are just confusing, and as soon as you find the decryption keys, you can decrypt them. Even code written in C or C ++, distributed as a binary file, can be programmed with feedback with sufficient time, tools and reasonably smart hackers.

You want it to be protected, you store it on your servers and only allow access through the network API.

+13
source share

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?

+3
source share

All Articles