[R] Sourcing encrypted files

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Sep 18 08:47:57 CEST 2007


On Mon, 17 Sep 2007, Dennis Fisher wrote:

> Colleagues,
>
> I have an unusual problem; I am wondering whether anyone has dealt
> with it and found a solution.
>
> I have a script that needs to be encrypted.  R will then be run on
> the script.  There are various means to decrypt the file, some of
> which leave the decrypted code on the hard drive for an excessive
> period.
>
> One means that I have considered to deal with this is the following
> (the unix code is not correct, just sufficient to communicate the idea):
> 	system("decrypt ...")
> 	system("rm encrypted file")
> 	source(decrypted file)
> 	system("rm decrypted file")
>
> Another approach would be to pipe the decrypted version to R in the
> command line (as it is being decrypted).  Obviously, this could be
> done with R < decryptedFile but this leaves the decrypted code
> exposed.  Is there some other means to accomplish my goals using
> something on the command line?

That's not what I understand by 'to pipe'.  You could use a pipe() 
connection with source() if you had a pipeline decrypter, either

decrypt filename | Rscript

or

source(pipe("decrypt filename"))

Those would be slightly safer as the decrypted source code is (probably) 
never written to the file system.

I am not sure what you are trying to achieve: since the R code is going to 
be decrypted it will be possible (and I suspect easy) to get hold of the 
decrypted version.  (Consider for example running a modified version of 
source() that dumped out the parse tree.)  Using a package to read the 
encrypted file and feed the decrypted source to the parser at C level an 
expression at a time would make this harder to circumvent.

(Unlike Marc Schwartz, I am presuming the aim is to protect scripts from 
casual inspection on someone else's machine: as Marc says there are better 
ways to protect code and data on your own systems.)


> Of note, the scripts are not terribly long - 50-200 lines each.
>
> Thanks
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-415-564-2220
> www.PLessThan.com
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list