Archive for the 'Mac' Category


Augmented Reality in Java 0


I recently found this amazing bit of work being done in Japan that allows you to do augmented reality in java all you need is a webcam and to run the webstart!

Sample Screen

Full credit goes to the guys who created this awesome bit of software. It took some digging around and google transalating (most of the site is in japanese) but heres what you need:

The Webstart Link: http://www.ylab.ai.kyutech.ac.jp/~shiva/jws/nyartoolkit/simplelite.jnlp

You also need to print out this file, as this is what the app is looking for via the webcam.

Sample PDF

All you need to do is run the webstart, print that file off and then move it about in front of your webcam. From what I can understand on the website it works on windows and mac (i’d assume linux as well) but my tests on windows didn’t go so well although it worked fine on a mac!

Its great to see they have ported it to Android as well as a bunch of other platforms, makes me wonder how hard it would be to port to Objective C for my iPhone!

Chris


Encrypting Files with an RFID Key 0

I have recently, just out of pure curiosity, picked up a Phidgets RFID Kit which consisits of an RFID scanner, a set of RFID tags (key chain, card, coins) and a disc with some software on it. After booting up their various sample code and seeing the thing in action (it works great by the way and has a nice java api) i couldn’t help but come up with a little project for myself (at the time i was watching spooks on tv and looking forward to the new James Bond film, so was thinking about cool spy gadgets). How great would it be if you could send someone a file that was encrypted, but they needed a physical key to open it?

What follows is my experince with the RFID kit and how I managed to get this up and running!

Overview

The basic idea of this system is that it will show a proof of concept of using RFID’s as a security key in encryption, as such ill just encrypt some text for now. What im aiming to achieve is that I can enter some text into a GUI, choose my encrypt or decrypt option, swipe my card and instantly see my data get encrypted!

To make life easier ill just use some standard DES encryption in java and a pretty simple GUI to tie it all together, obviously we can add some nice touches to the GUI to make it a little bit of a filthy rich client.

The Basics

Now what cool spy program would be complete without a cool spy GUI? Rather than spend all my time on the GUI, which was quite tempting I used a few tricks to speed things up. First I set the window to undecorated (for no real reason) then I used some overlayable components from the Jide Common Library to get a progress icon as things were encrypted and finally 2 radio buttons to choose encrypt or decrypt with only an exit button to press (that should confuse people trying to access your data!). The end result is this:

Encryption

For the encryption I plan to use some simple java cryptography using a DES Cypher and a key that is orignally hard coded, later on we will use the RFID chip as the key.

Generating the key is pretty easy, with a given string you need to get the bytes of the string (most encryption you will find works at a byte level), after that we need to create a key spec based on those bytes and finally get a secret key for our type of cypher with that key spec. It all sounds a bit complicated but in reality is 4 lines of code from string to SecretKey

String encryptionKey = "IAMTHEKEY";
 byte[] keyAsBytes = encryptionKey.getBytes("UTF-8");
 KeySpec keySpec = new DESKeySpec(keyAsBytes);
 SecretKey key = SecretKeyFactory.getInstance("DES").generateSecret(keySpec);

The second stage of encryption, once all the objects are set up, is just a case of converting the data you want to encrypt to bytes and encrypting it, in our example we also encode those bytes as a string so we can use them in the GUI. 3 lines of code later and you will have an encrpyted string.

byte[] bytes = str.getBytes("UTF8");
 byte[] encrypted = ecipher.doFinal(bytes);
 return new BASE64Encoder().encode(encrypted);

Im sure you can figure out how to do the reverse (or just grab the source from the bottom of the page).

RFID Addon

At this point we can encrpyt strings and decypt them, I have plugged all of that into my GUI and the final stage is just to react to RFID events from the phidgets device. At this point you could panic about having to do some low level IO coding, JNI or god knows what to get access to the RFID input, but thankfully Phidgets come with a nice java API.

To set up the reader all we need to do is the following, create an RFID reader and attach a listener for the RFID tag being placed onto the reader at that point we will call our internal encrpyt or decrypt methods based on the current radio button.

rfid = new RFIDPhidget();
rfid.addTagGainListener(new TagGainListener(){
void tagGained(TagGainEvent e){
//here we can start the encryption based on the tags ID
}
});


Summary

Ok before anyone starts having a go saying the RFID value isn’t a long enough key to use etc, this is just for fun!

What this does show is that seemingly complex functionality is very acessible these days. Ok RFID cards can be copied, but what if I also add a password to the system? What if I scan the area for bluetooth devices and check my phone is about?

Its a pretty fun little project and if I get some time ill hook into my laptops bluetooth to improve the key and maybe stop encrypting strings but actually encrypt files instead! Heres some pics of it running, and how it was all set up.

The laptop with the phidget installed and the software running

Heres the text again after decryption

Heres the encrypted text

Source Code for this project is here and released under my usual terms. Note you wil need to download Jide and get phidgets installed on your platform.