Monday 18 August 2008

KeyCzar quickfix fixed

Some of you might recall my using a batch 'quickfix' in a previous post about Google KeyCzar: creating the RSA public and private keys using batch, to work around a small issue whereby filenames ended up being concatenated to the folder name (e.g. rsakeysmeta instead of rsakeys\meta).

A few hours after posting, I eureka-d that adding \ to the folder variables would probably fix it much more neatly - and now I have found the time to verify this, it does :-).

I fixed the previous post accordingly and here is the uninterrupted simplified version of the batch for anyone interested:

@echo off
setlocal enabledelayedexpansion

:init
set java=java
if exist "C:\Program Files\Java\jre1.6.0_05\bin\java.exe" set java="C:\Program Files\Java\jre1.6.0_05\bin\java.exe"
if exist "C:\Program Files\Java\jre1.6.0_07\bin\java.exe" set java="C:\Program Files\Java\jre1.6.0_07\bin\java.exe"
if not exist %java% goto java_nf

set parent=..
set keyczar=keyczar05b.jar
set gson=gson-1.1.1.jar
set log4j=log4j-1.2.15.jar

if not exist %parent%\%keyczar% goto keyczar_jar_nf
if not exist %parent%\%gson% goto gson_jar_nf
if not exist %parent%\%log4j% goto log4j_jar_nf

goto create_keys

:create_keys
set location=rsakeys\
set public=publickeys\

if not exist %location%%public% mkdir %location%%public%

echo Creating key set
%java% -classpath %parent%/%keyczar%;%parent%/%gson%;%parent%/%log4j% org.keyczar.KeyczarTool create --location=%location% --purpose=crypt --asymmetric=rsa
echo Creating private decryption key
%java% -classpath %parent%/%keyczar%;%parent%/%gson%;%parent%/%log4j% org.keyczar.KeyczarTool addkey --location=%location% --status=primary
echo Creating public encryption (primary) key
%java% -classpath %parent%/%keyczar%;%parent%/%gson%;%parent%/%log4j% org.keyczar.KeyczarTool pubkey --location=%location% --status=active --destination=%location%%public%
goto eof

:java_nf
echo Cannot find java
goto eof

:keyczar_jar_nf
echo Cannot find keyczar jar
goto eof

:gson_jar_nf
echo Cannot find gson jar
goto eof

:log4j_jar_nf
echo Cannot find log4j jar
goto eof

:eof
echo Press any key to quit
pause > NUL
goto blackhole

:blackhole

Well, that's it. Much neater and quite as functional!

Please refer to the previous post for more information on what is actually happening here.

You can also read the second part of the post which covers how to use the KeyCzar library in Java for asymmetric RSA encryption/decryption (using the keys we just created with the above batch file).

Thoughts?

No comments:

Online Marketing
Add blog to our blog directory blog search directory Blog Directory Blogarama - The Blog Directory