Re: Transparent Encryption and Decryption On Windows

2007-05-23 Thread Tom Purl
On Wed, May 23, 2007 11:05 am, Allan Wind wrote:
> On 2007-05-23T09:59:22-0500, Tom Purl wrote:
>> Is there anyone else who's usuing gpg or openssl
>> with Vim?
>
> I use one of the gpg plugins all the time:
> http://www.vim.org/scripts/script.php?script_id=1751

Problem solved.

Thanks Allan.  I was hoping to find an openssl solution since I'm so
familiar with it and prefer symmetric to asymmetric encryption.

However, since the gpg.vim plugin is so robust, and since it works with
Windows, I decided to take a closer look at gpg.  It turns out that I
can use symmetric (password-only) encryption with gpg, and that the
gpg.vim plugin supports it very well.

I therefore "converted" my old encrypted file to use gpg encryption
using the following commands on Windows:

c:\foo> dir
05/23/2007  10:42 AM   312 secret.txt.des3

c:\foo> openssl enc -d -des3 -in .\secret.txt.des3 -out .\secret.txt
(entered password)

c:\foo> dir
05/23/2007  10:45 AM   312 secret.txt
05/23/2007  10:42 AM   312 secret.txt.des3

c:\foo> gpg --symmetric --output .\secret.txt.gpg .\secret.txt
(entered password twice)

c:\foo> dir
05/23/2007  10:45 AM   312 secret.txt
05/23/2007  10:42 AM   312 secret.txt.des3
05/23/2007  10:46 AM   312 secret.txt.gpg

c:\foo> sdelete .\secret.txt

c:\foo> dir
05/23/2007  10:42 AM   312 secret.txt.des3
05/23/2007  10:46 AM   312 secret.txt.gpg

I could then transparently edit the file using vim once I had installed
the gpg.vim plugin.

Thanks to everyone for their help, especially Markus Braun for writing
such an excellent plugin.

Tom Purl




Re: Transparent Encryption and Decryption On Windows

2007-05-23 Thread Allan Wind
On 2007-05-23T09:59:22-0500, Tom Purl wrote:
> Is there anyone else who's usuing gpg or openssl
> with Vim?

I use one of the gpg plugins all the time:
http://www.vim.org/scripts/script.php?script_id=1751


/Allan


Transparent Encryption and Decryption On Windows

2007-05-23 Thread Tom Purl
I like to use OpenSSL to encrypt some files on my hard drive.  I cobbled
together the following script that allows me to "transparently" view and
updated OpenSSL-encrypted docs using vim on Linux:

augroup encrypted
au!

" First make sure nothing is written to ~/.viminfo while editing
" an encrypted file.
autocmd BufReadPre,FileReadPre  *.des3 set viminfo=
" We don't want a swap file, as it write unencrypted data to disk
autocmd BufReadPre,FileReadPre  *.des3 set noswapfile
" Switch to binary mode to read the encrypted file
autocmd BufReadPre,FileReadPre  *.des3 set bin
autocmd BufReadPre,FileReadPre  *.des3 let ch_save =
&ch|set ch=2
autocmd BufReadPre,FileReadPre  *.des3 let shsave=&sh
autocmd BufReadPre,FileReadPre  *.des3 let &sh='sh'
autocmd BufReadPre,FileReadPre  *.des3 let ch_save =
&ch|set ch=2
autocmd BufReadPost,FileReadPost*.des3 '[,']!openssl enc
-d -des3 2> /dev/null
autocmd BufReadPost,FileReadPost*.des3 let &sh=shsave

" Switch to normal mode for editing
autocmd BufReadPost,FileReadPost*.des3 set nobin
autocmd BufReadPost,FileReadPost*.des3 let &ch =
ch_save|unlet ch_save
autocmd BufReadPost,FileReadPost*.des3 execute ":doautocmd
BufReadPost " . expand("%:r")

" Convert all text to encrypted text before writing
autocmd BufWritePre,FileWritePre*.des3 set bin
autocmd BufWritePre,FileWritePre*.des3 let shsave=&sh
autocmd BufWritePre,FileWritePre*.des3 let &sh='sh'
autocmd BufWritePre,FileWritePre*.des3 '[,']!openssl enc
-e -des3 -salt 2>/dev/null
autocmd BufWritePre,FileWritePre*.des3 let &sh=shsave

" Undo the encryption so we are back in the normal text, directly
after the
" file has been written.
autocmd BufWritePost,FileWritePost  *.des3 silent u
autocmd BufWritePost,FileWritePost  *.des3 set nobin
augroup END


Basically, when I try to open a file with a "des3" file extension, this
chunk of code is executed.

To get this to work on Windows, I changed the "openssl" lines to the
following:

autocmd BufReadPost,FileReadPost*.des3
'[,']!C:\OpenSSL\bin\openssl.exe enc -d -des3 2> /dev/null
...
autocmd BufWritePre,FileWritePre*.des3
'[,']!C:\OpenSSL\bin\openssl.exe enc -e -des3 -salt 2>/dev/null

Also, I commented out the "let &sh='sh'" lines, since I get the
following value when I execute the ":echo &sh" command:

C:\WINDOWS\system32\cmd.exe

However, when I try to open an encrypted file using this function, I get
the following error:

c:> gvim .\secret.txt.des3
".\secret.txt.des3" [noeol][unix] 10L, 1304C
shell returned 1
10 lines filtered
Press ENTER or type command to continue
...
'sh' is not recognized as an internal or external command,
operable program or batch file.

The weird part is that I commented out all of the lines that explicitly
reference 'sh'.

What am I doing wrong?  Is there anyone else who's usuing gpg or openssl
with Vim?

Thanks in advance!

Tom Purl