Re: [R] Help with decrypting

2016-11-09 Thread MacQueen, Don
Thanks, David.

It does read without error using readBin. And using file.info as you
suggest seem to be a step in the right direction (the length of foo agrees
with 'wc -l' on the file). I just get different errors on subsequent
attempts to use it.

(I should have mentioned in the beginning, whatever I do, I'd like it to
work on both Mac and Linux.)

And thanks again to all three of you. I'm about ready to give up on an R
solution, and call an external script as Marc suggests.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 11/9/16, 11:27 AM, "David Winsemius"  wrote:

>
>> On Nov 9, 2016, at 10:35 AM, MacQueen, Don  wrote:
>> 
>> Bob,
>> 
>> Thanks for responding. I've tried the functions in bcrypt, and get, for
>> example,
>> 
>>> infl <- 'path.to.the.encrypted.file'
>>> junk <- 'the.password'
>>> foo <- readLines(infl)
>> Warning message:
>> In readLines(infl) :
>>  incomplete final line found on 'path.to.the.encrypted.file'
>
>I would not have expected that to succeed. readLines drops cr's and lf's
>and it certainly seems possible that those characters might be encrypted
>values randomly sprinkled through the image. What happens when you read
>it as raw? (may need to first get `file.info` to determine file length.)
>
>perhaps something along the lines of
>
>foo <- readBin( infl, "raw", file.info(infl)[1, "size"])
>
>-- 
>David
>
>
>>> tmp <- checkpw(junk, foo)
>> Error in hashpw(password, hash) : Invalid salt
>> 
>> Thus demonstrating that I don't know what I'm doing.
>> 
>> If it's easy to expand, as you mention, I would indeed appreciate it.
>> 
>> -Don
>> 
>> 
>> -- 
>> Don MacQueen
>> 
>> Lawrence Livermore National Laboratory
>> 7000 East Ave., L-627
>> Livermore, CA 94550
>> 925-423-1062
>> 
>> 
>> 
>> 
>> 
>> On 11/7/16, 5:29 PM, "Bob Rudis"  wrote:
>> 
>>> Perhaps https://cran.r-project.org/web/packages/bcrypt/index.html
>>> might be of assistance.
>>> 
>>> If not, drop a note back to the list as it'll be trivial to expand on
>>> that to give you an R alternative to Perl.
>>> 
>>> On Mon, Nov 7, 2016 at 5:47 PM, MacQueen, Don 
>>>wrote:
 I have a file containing encrypted contents. The contents can be
 decrypted
 using perl, like this:
 
 open (FILEHANDLE, "/path/to/file")
 chomp ($ciphertext = );
 
 
 use Crypt::CBC;
 $cipher = Crypt::CBC->new( -key=> 'my secret key',
   -cipher => 'Blowfish'
  );
 
 $plaintext  = $cipher->decrypt($ciphertext);
 
 
 (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)
 
 M goal is to have the value of $plaintext in an R object, so, is there
 an
 R equivalent to this decrypt() perl function?
 
 I've found R packages
  bcrypt
  sodium
 that appear to have potential, but I don't understand this business
well
 enough to figure out how to use them, if indeed they can be used, for
 this. Help would be much appreciated.
 
 Thanks
 -Don
 
 --
 Don MacQueen
 
 Lawrence Livermore National Laboratory
 7000 East Ave., L-627
 Livermore, CA 94550
 925-423-1062
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 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.
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
>David Winsemius
>Alameda, CA, USA
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Help with decrypting

2016-11-09 Thread Marc Schwartz
Hi Don,

Since there is not a current R package implementation of the blowfish algorithm 
for encyrpt/decrypt, as far as I can tell, your only options via R would be to 
call an external script/program that provides that functionality from within R, 
or consider integrating one of the compiled language versions (e.g. C/C++) into 
an R package that you would create, presuming that the licenses for those 
implementations would allow for that. The algorithm itself is public domain 
thanks to Bruce.

There are "interpreted" versions of the Blowfish implementation available, 
including one in pure Perl in the Crypt module and a Visual Basic version, 
which you could possibly follow and re-write in pure R. But going that route 
risks introducing errors in the implementation, which needless to say, is not a 
risk you really want to take.

However, in general, encrypt/decrypt algorithms are designed to be 
intentionally difficult and are usually CPU bound, since they are doing 
multiple rounds of bit-level manipulations. Thus, using interpreted program 
versions for anything but a small amount of text is typically going to be 
problematic compute time-wise.

That is why they are generally implemented in compiled languages or for more 
complex algorithms, in firmware.

BTW, vis-a-vis your reply back to Bob, as I noted, the variant of Blowfish that 
is in the bcrypt package on CRAN will not do what you want. It is designed to 
do one thing, encrypt passwords using a non-reversible algorithm (hash) for 
storage and later comparison with an entered cleartext password, that is 
encrypted using the same algorithm. 

Regards,

Marc


> On Nov 9, 2016, at 12:11 PM, MacQueen, Don <macque...@llnl.gov> wrote:
> 
> Thanks, Marc,
> 
> Unfortunately, I didn't choose the encryption method. My (only) need is to be 
> able to decrypt an existing file that is maintained by others. I am able to 
> use system() on a simple perl script to do the job, but I'm hoping for an 
> R-only solution, primarily for portability.
> 
> -Don
> 
> -- 
> Don MacQueen
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> 
> 
> From: Marc Schwartz <marc_schwa...@me.com <mailto:marc_schwa...@me.com>>
> Date: Monday, November 7, 2016 at 3:30 PM
> To: dh m <macque...@llnl.gov <mailto:macque...@llnl.gov>>
> Cc: R-help <R-help@r-project.org <mailto:R-help@r-project.org>>
> Subject: Re: [R] Help with decrypting
> 
> 
>> On Nov 7, 2016, at 4:47 PM, MacQueen, Don <macque...@llnl.gov 
>> <mailto:macque...@llnl.gov>> wrote:
>> 
>> I have a file containing encrypted contents. The contents can be decrypted
>> using perl, like this:
>> 
>> open (FILEHANDLE, "/path/to/file")
>> chomp ($ciphertext = );
>> 
>> 
>> use Crypt::CBC;
>> $cipher = Crypt::CBC->new( -key=> 'my secret key',
>>   -cipher => 'Blowfish'
>>  );
>> 
>> $plaintext  = $cipher->decrypt($ciphertext);
>> 
>> 
>> (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm 
>> <http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm>)
>> 
>> M goal is to have the value of $plaintext in an R object, so, is there an
>> R equivalent to this decrypt() perl function?
>> 
>> I've found R packages
>>  bcrypt
>>  sodium
>> that appear to have potential, but I don't understand this business well
>> enough to figure out how to use them, if indeed they can be used, for
>> this. Help would be much appreciated.
>> 
>> Thanks
>> -Don
>> 
> 
> 
> 
> Hi Don,
> 
> Blowfish is Bruce Schneier's algorithm from the early 90's, which even Bruce 
> suggested some time ago not be used. Bruce has some alternative Blowfish 
> implementations available via his web site:
> 
>   https://www.schneier.com/academic/blowfish/download.html 
> <https://www.schneier.com/academic/blowfish/download.html>
> 
> and there is a link there for some third party products that still have it 
> and might provide for a CLI based interface as an alternative (e.g. GnuPG) if 
> you need to use it.
> 
> From what I can tell, 'sodium' does not support Blowfish and the 
> implementation in bcrypt, if I am reading correctly, only provides for a 
> one-way hash implementation, as opposed to encrypt/decrypt functions.
> 
> Thus, barring that my searching for alternative R implementations of Blowfish 
> resulted in a Type II error, I do not see any R implementations of Blowfish 
> that support encrypt/decrypt.
> 
> If you want to use the Perl module implementation via R, you can take a look 
> at my WriteXLS package on

Re: [R] Help with decrypting

2016-11-09 Thread David Winsemius

> On Nov 9, 2016, at 10:35 AM, MacQueen, Don  wrote:
> 
> Bob,
> 
> Thanks for responding. I've tried the functions in bcrypt, and get, for
> example,
> 
>> infl <- 'path.to.the.encrypted.file'
>> junk <- 'the.password'
>> foo <- readLines(infl)
> Warning message:
> In readLines(infl) :
>  incomplete final line found on 'path.to.the.encrypted.file'

I would not have expected that to succeed. readLines drops cr's and lf's and it 
certainly seems possible that those characters might be encrypted values 
randomly sprinkled through the image. What happens when you read it as raw? 
(may need to first get `file.info` to determine file length.)

perhaps something along the lines of 

foo <- readBin( infl, "raw", file.info(infl)[1, "size"])

-- 
David


>> tmp <- checkpw(junk, foo)
> Error in hashpw(password, hash) : Invalid salt
> 
> Thus demonstrating that I don't know what I'm doing.
> 
> If it's easy to expand, as you mention, I would indeed appreciate it.
> 
> -Don
> 
> 
> -- 
> Don MacQueen
> 
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> 
> 
> 
> 
> 
> On 11/7/16, 5:29 PM, "Bob Rudis"  wrote:
> 
>> Perhaps https://cran.r-project.org/web/packages/bcrypt/index.html
>> might be of assistance.
>> 
>> If not, drop a note back to the list as it'll be trivial to expand on
>> that to give you an R alternative to Perl.
>> 
>> On Mon, Nov 7, 2016 at 5:47 PM, MacQueen, Don  wrote:
>>> I have a file containing encrypted contents. The contents can be
>>> decrypted
>>> using perl, like this:
>>> 
>>> open (FILEHANDLE, "/path/to/file")
>>> chomp ($ciphertext = );
>>> 
>>> 
>>> use Crypt::CBC;
>>> $cipher = Crypt::CBC->new( -key=> 'my secret key',
>>>   -cipher => 'Blowfish'
>>>  );
>>> 
>>> $plaintext  = $cipher->decrypt($ciphertext);
>>> 
>>> 
>>> (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)
>>> 
>>> M goal is to have the value of $plaintext in an R object, so, is there
>>> an
>>> R equivalent to this decrypt() perl function?
>>> 
>>> I've found R packages
>>>  bcrypt
>>>  sodium
>>> that appear to have potential, but I don't understand this business well
>>> enough to figure out how to use them, if indeed they can be used, for
>>> this. Help would be much appreciated.
>>> 
>>> Thanks
>>> -Don
>>> 
>>> --
>>> Don MacQueen
>>> 
>>> Lawrence Livermore National Laboratory
>>> 7000 East Ave., L-627
>>> Livermore, CA 94550
>>> 925-423-1062
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Help with decrypting

2016-11-09 Thread MacQueen, Don
Bob,

Thanks for responding. I've tried the functions in bcrypt, and get, for
example,

> infl <- 'path.to.the.encrypted.file'
> junk <- 'the.password'
> foo <- readLines(infl)
Warning message:
In readLines(infl) :
  incomplete final line found on 'path.to.the.encrypted.file'
> tmp <- checkpw(junk, foo)
Error in hashpw(password, hash) : Invalid salt

Thus demonstrating that I don't know what I'm doing.

If it's easy to expand, as you mention, I would indeed appreciate it.

-Don


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 11/7/16, 5:29 PM, "Bob Rudis"  wrote:

>Perhaps https://cran.r-project.org/web/packages/bcrypt/index.html
>might be of assistance.
>
>If not, drop a note back to the list as it'll be trivial to expand on
>that to give you an R alternative to Perl.
>
>On Mon, Nov 7, 2016 at 5:47 PM, MacQueen, Don  wrote:
>> I have a file containing encrypted contents. The contents can be
>>decrypted
>> using perl, like this:
>>
>> open (FILEHANDLE, "/path/to/file")
>> chomp ($ciphertext = );
>>
>>
>> use Crypt::CBC;
>> $cipher = Crypt::CBC->new( -key=> 'my secret key',
>>-cipher => 'Blowfish'
>>   );
>>
>> $plaintext  = $cipher->decrypt($ciphertext);
>>
>>
>> (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)
>>
>> M goal is to have the value of $plaintext in an R object, so, is there
>>an
>> R equivalent to this decrypt() perl function?
>>
>> I've found R packages
>>   bcrypt
>>   sodium
>> that appear to have potential, but I don't understand this business well
>> enough to figure out how to use them, if indeed they can be used, for
>> this. Help would be much appreciated.
>>
>> Thanks
>> -Don
>>
>> --
>> Don MacQueen
>>
>> Lawrence Livermore National Laboratory
>> 7000 East Ave., L-627
>> Livermore, CA 94550
>> 925-423-1062
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Help with decrypting

2016-11-09 Thread MacQueen, Don
Thanks, Marc,

Unfortunately, I didn't choose the encryption method. My (only) need is to be 
able to decrypt an existing file that is maintained by others. I am able to use 
system() on a simple perl script to do the job, but I'm hoping for an R-only 
solution, primarily for portability.

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062


From: Marc Schwartz <marc_schwa...@me.com<mailto:marc_schwa...@me.com>>
Date: Monday, November 7, 2016 at 3:30 PM
To: dh m <macque...@llnl.gov<mailto:macque...@llnl.gov>>
Cc: R-help <R-help@r-project.org<mailto:R-help@r-project.org>>
Subject: Re: [R] Help with decrypting


On Nov 7, 2016, at 4:47 PM, MacQueen, Don 
<macque...@llnl.gov<mailto:macque...@llnl.gov>> wrote:

I have a file containing encrypted contents. The contents can be decrypted
using perl, like this:

open (FILEHANDLE, "/path/to/file")
chomp ($ciphertext = );


use Crypt::CBC;
$cipher = Crypt::CBC->new( -key=> 'my secret key',
  -cipher => 'Blowfish'
 );

$plaintext  = $cipher->decrypt($ciphertext);


(See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)

M goal is to have the value of $plaintext in an R object, so, is there an
R equivalent to this decrypt() perl function?

I've found R packages
 bcrypt
 sodium
that appear to have potential, but I don't understand this business well
enough to figure out how to use them, if indeed they can be used, for
this. Help would be much appreciated.

Thanks
-Don



Hi Don,

Blowfish is Bruce Schneier's algorithm from the early 90's, which even Bruce 
suggested some time ago not be used. Bruce has some alternative Blowfish 
implementations available via his web site:

  https://www.schneier.com/academic/blowfish/download.html

and there is a link there for some third party products that still have it and 
might provide for a CLI based interface as an alternative (e.g. GnuPG) if you 
need to use it.

>From what I can tell, 'sodium' does not support Blowfish and the 
>implementation in bcrypt, if I am reading correctly, only provides for a 
>one-way hash implementation, as opposed to encrypt/decrypt functions.

Thus, barring that my searching for alternative R implementations of Blowfish 
resulted in a Type II error, I do not see any R implementations of Blowfish 
that support encrypt/decrypt.

If you want to use the Perl module implementation via R, you can take a look at 
my WriteXLS package on GitHub:

  https://github.com/marcschwartz/WriteXLS

and see how I call Perl scripts within WriteXLS.R:

  https://github.com/marcschwartz/WriteXLS/blob/master/R/WriteXLS.R

around line 242.

That might provide one method for you.

That all being said, as per Bruce's recommendation, there are "better" 
encryption/decryption algorithms these days (some in the 'digest' package by 
Dirk), depending upon who you are trying to protect the data from... :-)

Regards,

Marc Schwartz



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Help with decrypting

2016-11-07 Thread Bob Rudis
Perhaps https://cran.r-project.org/web/packages/bcrypt/index.html
might be of assistance.

If not, drop a note back to the list as it'll be trivial to expand on
that to give you an R alternative to Perl.

On Mon, Nov 7, 2016 at 5:47 PM, MacQueen, Don  wrote:
> I have a file containing encrypted contents. The contents can be decrypted
> using perl, like this:
>
> open (FILEHANDLE, "/path/to/file")
> chomp ($ciphertext = );
>
>
> use Crypt::CBC;
> $cipher = Crypt::CBC->new( -key=> 'my secret key',
>-cipher => 'Blowfish'
>   );
>
> $plaintext  = $cipher->decrypt($ciphertext);
>
>
> (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)
>
> M goal is to have the value of $plaintext in an R object, so, is there an
> R equivalent to this decrypt() perl function?
>
> I've found R packages
>   bcrypt
>   sodium
> that appear to have potential, but I don't understand this business well
> enough to figure out how to use them, if indeed they can be used, for
> this. Help would be much appreciated.
>
> Thanks
> -Don
>
> --
> Don MacQueen
>
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Help with decrypting

2016-11-07 Thread Marc Schwartz

> On Nov 7, 2016, at 4:47 PM, MacQueen, Don  wrote:
> 
> I have a file containing encrypted contents. The contents can be decrypted
> using perl, like this:
> 
> open (FILEHANDLE, "/path/to/file")
> chomp ($ciphertext = );
> 
> 
> use Crypt::CBC;
> $cipher = Crypt::CBC->new( -key=> 'my secret key',
>   -cipher => 'Blowfish'
>  );
> 
> $plaintext  = $cipher->decrypt($ciphertext);
> 
> 
> (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)
> 
> M goal is to have the value of $plaintext in an R object, so, is there an
> R equivalent to this decrypt() perl function?
> 
> I've found R packages
>  bcrypt
>  sodium
> that appear to have potential, but I don't understand this business well
> enough to figure out how to use them, if indeed they can be used, for
> this. Help would be much appreciated.
> 
> Thanks
> -Don
> 



Hi Don,

Blowfish is Bruce Schneier's algorithm from the early 90's, which even Bruce 
suggested some time ago not be used. Bruce has some alternative Blowfish 
implementations available via his web site:

  https://www.schneier.com/academic/blowfish/download.html 


and there is a link there for some third party products that still have it and 
might provide for a CLI based interface as an alternative (e.g. GnuPG) if you 
need to use it.

>From what I can tell, 'sodium' does not support Blowfish and the 
>implementation in bcrypt, if I am reading correctly, only provides for a 
>one-way hash implementation, as opposed to encrypt/decrypt functions.

Thus, barring that my searching for alternative R implementations of Blowfish 
resulted in a Type II error, I do not see any R implementations of Blowfish 
that support encrypt/decrypt.

If you want to use the Perl module implementation via R, you can take a look at 
my WriteXLS package on GitHub:

  https://github.com/marcschwartz/WriteXLS 


and see how I call Perl scripts within WriteXLS.R:

  https://github.com/marcschwartz/WriteXLS/blob/master/R/WriteXLS.R 


around line 242.

That might provide one method for you.

That all being said, as per Bruce's recommendation, there are "better" 
encryption/decryption algorithms these days (some in the 'digest' package by 
Dirk), depending upon who you are trying to protect the data from... :-)

Regards,

Marc Schwartz



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Help with decrypting

2016-11-07 Thread MacQueen, Don
I have a file containing encrypted contents. The contents can be decrypted
using perl, like this:

open (FILEHANDLE, "/path/to/file")
chomp ($ciphertext = );


use Crypt::CBC;
$cipher = Crypt::CBC->new( -key=> 'my secret key',
   -cipher => 'Blowfish'
  );

$plaintext  = $cipher->decrypt($ciphertext);


(See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)

M goal is to have the value of $plaintext in an R object, so, is there an
R equivalent to this decrypt() perl function?

I've found R packages
  bcrypt
  sodium
that appear to have potential, but I don't understand this business well
enough to figure out how to use them, if indeed they can be used, for
this. Help would be much appreciated.

Thanks
-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.