WWDC 2010 Keynote

I need to prefix everything I am about to say with a disclaimer:  I am not an Apple hater; I just honestly don’t understand the hype.

Apple is a great hardware company; their products are truly stunning.  I use my MacBook Pro more than any of my other computers, and I’m the defacto Mac-guy at work.  I don’t personally own an iPad/iPhone/iPod (and never have), but everybody else at my house does.   I don’t dislike Apple or their products … I very much dislike a certain rabid population of their fan base.

As a software company, I think that Apple is about average.  It’s easier to engineer software that will only run on your hardware than it is to attempt to make software that will try to handle whatever you throw at it.  Apple products (hardware/software combined) work quite well together, but there’s two sides to that coin.

So, anyway, back to the topic…

Every year, just like every other geek on the planet, I get sucked into the WWDC Keynote.  This year I was a little disappointed.

iOS

We already knew about iOS 4.  We knew what it was going to offer and quite frankly, this update is not about innovation as much as it is catching up.  I don’t always buy the quote “we didn’t do it first, but we do it best”.  Things like folders and multitasking aren’t innovative (or impressive) on a smart phone … even if you “do them better”.

iPhone 4

It’s pretty slick, but it’s not a game changer.  If it were on my carrier of choice, I might be tempted to get one.  Maybe it’s not all that impressive because we’ve seen it before … no real surprises there.

FaceTime

Really, come on…  Sure, it’s cool that this is on a cell phone, but it is really the next big thing?  I don’t know about you, but I’ve been video conferencing for years.  I’m also pretty damn sure I’d rather do it with a laptop then by holding my iPhone in my hand too.  And what if my grandmom doesn’t have an iPhone?

Now, Apple, develop an open video calling/conferencing spec that we could implement on our phones, computers, TV’s, and toasters  and I’ll jump on the bandwagon.  iPhone users video conferencing with iPhone user’s isn’t overly impressive.  I don’t know, if it were truly about changing the way we communicate, it wouldn’t just be about changing the way iPhone users communicate.

Mac Products

Maybe it’s just me, but it seems that Apple is ignoring it’s laptop/desktop line lately.  To quote Steve Jobs, not everybody needs a truck … but those of us that drive trucks would like a to be thrown a bone once in a while.  Let’s not forget that (at least for now), there is no iPhone/iPad without the developers sitting behind their MacBooks (that is, until the iPad get Xcode).

It’s quite possible though, that the Mac line isn’t in need of updating.  They are not really the company’s cash cow anyway … They’re just the incubator that hatches the little baby cash cows.

Maybe next year, the current crop will be sufficiently lagging behind to deserve a bit of an update.


All-in-all, I know all that sounds hateful, but I miss the days when Apple made me actually want to buy their products.  Today, I was just left with a “so what” attitude.

Encrypting and Decrypting Files with Java

This information is old and crufty. There’s still some decent stuff here, but check up the updated version here: https://cryptofreek.org/2012/12/10/encrypting-and-decrypting-java-part-2/

I’m working on a little app that can do simple and portable file encryption across different operating systems.  Something I can put on a thumb drive to encrypt files so that when I inevitably loose the drive, all my documents aren’t public knowledge.

Most modern operating systems offer file encryption … a lot of new external drives and flash drives come with programs that will encrypt the filesystem … but all of those things are a huge pain when you live on multiple platforms.  I move files around between my Windows, Mac, and Solaris computers at work and my Linux boxes at home.  I need something simple to get the job done that works on all of the above.  Java lets me do this pretty easily, let’s take a look …

Cryptography is still a bit of a black art, even when looking at high level API’s like we’ll see in this example.  There are any number of different ways to do this using different types of keys and algorithms.  In this example, I’ll be using a simple password based symmetric key with Triple DES (DESede) encryption (PKCS #5, RFC2898).  Please see the RFC doc for a definition of terminology.

Creating the cipher

The first step is generating an encryption key and using it to create a cipher:

public static Cipher createCipher( char[] password,
                                   int nMode,
                                   byte[] baSalt,
                                   int nInterations ) throws NoSuchAlgorithmException,
                                                     InvalidKeySpecException,
                                                     InvalidKeyException,
                                                     InvalidAlgorithmParameterException,
                                                     NoSuchPaddingException
{
  Cipher cipher = null;

  PBEParameterSpec pbeParamSpec = new PBEParameterSpec( baSalt, nInterations );

  PBEKeySpec pbeKeySpec = new PBEKeySpec( password );
  SecretKeyFactory keyFac = SecretKeyFactory.getInstance( "PBEWithSHA1AndDESede" );
  SecretKey key = keyFac.generateSecret( pbeKeySpec );

  cipher = Cipher.getInstance( "PBEWithSHA1AndDESede" );
  cipher.init( nMode, key, pbeParamSpec );

  return cipher;
}

Encrypting/Decrypting with IO Streams

Once the cipher is created, the crypto operation is as easy as reading and writing to IO streams. These could be any streams you could think of, but in this case we are using file streams:

public static void doCrypto( InputStream in, OutputStream out, Cipher cipher ) throws IOException
{
  CipherOutputStream cos = new CipherOutputStream( out, cipher );
  byte[] baChunck = new byte[1024];

  for( int nRead = 0; nRead >= 0; nRead = in.read( baChunck ) )
  {
    cos.write( baChunck, 0, nRead );
  }

  in.close();
  out.close();
  cos.close();
}

Done!

That’s it, here’s a full working example:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;

public class CCryptoUtils
{
  public static Cipher createCipher( char[] password,
                                     int nMode,
                                     byte[] baSalt,
                                     int nInterations ) throws NoSuchAlgorithmException,
                                                       InvalidKeySpecException,
                                                       InvalidKeyException,
                                                       InvalidAlgorithmParameterException,
                                                       NoSuchPaddingException
  {
    Cipher cipher = null;

    PBEParameterSpec pbeParamSpec = new PBEParameterSpec( baSalt, nInterations );

    PBEKeySpec pbeKeySpec = new PBEKeySpec( password );
    SecretKeyFactory keyFac = SecretKeyFactory.getInstance( "PBEWithSHA1AndDESede" );
    SecretKey key = keyFac.generateSecret( pbeKeySpec );

    cipher = Cipher.getInstance( "PBEWithSHA1AndDESede" );
    cipher.init( nMode, key, pbeParamSpec );

    return cipher;
  }

  public static void doCrypto( InputStream in, OutputStream out, Cipher cipher ) throws IOException
  {
    CipherOutputStream cos = new CipherOutputStream( out, cipher );
    byte[] baChunck = new byte[128];

    for( int nRead = 0; nRead >= 0; nRead = in.read( baChunck ) )
    {
      cos.write( baChunck, 0, nRead );
    }

    in.close();
    cos.close();
  }

  public static void doFileOperation( File fileIn,
                                      File fileOut,
                                      int nMode,
                                      char[] password,
                                      byte[] baSalt,
                                      int nIterations ) throws InvalidKeyException,
                                                       NoSuchAlgorithmException,
                                                       InvalidKeySpecException,
                                                       InvalidAlgorithmParameterException,
                                                       NoSuchPaddingException,
                                                       FileNotFoundException,
                                                       IOException
  {
    Cipher cipher = createCipher( password, nMode, baSalt, nIterations );
    doCrypto( new FileInputStream( fileIn ),
              new FileOutputStream( fileOut ),
              cipher );
  }

  public static void main( String[] args )
  {
    char[] password = "mypassword".toCharArray();
    byte[] baSalt = "'~7&03~/.".getBytes();
    int nIterations = 1;

    File fileToEncrypt = new File( "/Users/cryptofreek/Desktop/test.txt" );
    File fileEncrypted = new File( "/Users/cryptofreek/Desktop/test.txt.encrypted" );
    File fileDecrypted = new File( "/Users/cryptofreek/Desktop/test.txt.decrypted" );

    try
    {
      doFileOperation( fileToEncrypt,
                       fileEncrypted,
                       Cipher.ENCRYPT_MODE,
                       password,
                       baSalt,
                       nIterations );

      doFileOperation( fileEncrypted,
                       fileDecrypted,
                       Cipher.DECRYPT_MODE,
                       password,
                       baSalt,
                       nIterations );
    }
    catch( Exception e )
    {
      e.printStackTrace();
    }
  }
}

Update:  The real beauty of using IO streams like this is that you do not have to worry as much about Java’s heap space.  Your memory usage rarely grows past the chunk size specified in the “doCrypto()” function; even if you are operating on huge files.

home sick

I’m not sure exactly how it’s possible to be home sick for a place that I’ve never been, but that’s the situation I find myself in.  For the past year I’ve nearly irresistible urge to move to New Zealand, and it really strange that sometimes I want to be there so bad that it physically hurts.  If I wasn’t tied here for numerous reasons, I’d probably already be there.

I really don’t know what the deal is … maybe it’s the fact that I moved around a lot as a kid and I’m getting tired of the place I’ve been for the last 13 years … maybe it’s the climate and amazing landscapes … maybe the nerd in me just really wants to live in Middle Earth … I don’t know.

My wife and I have discussed it on a semi-serious basis, and she’s not totally opposed to the idea.  Although, I really think it’s just because she sees how badly I’d like to be there, and because she’s amazing and would follow me anywhere, she plays along.  We’ve looked into job opportunities and both our fields are on the lists for immediate and long term skilled immigrants.  We’ve looked at houses, schools, churches, jobs, hospitals, etc.

There is some pretty intriguing research in Type-1 diabetes coming out of New Zealand and Australia; some trials that are only available for residents.  That’s really exciting for us, as I’m treating a low blood sugar in my eight year old son as I type this.

I really kinda doubt that it’s ever gonna happen … but a boy can dream … can’t he?

Nerds are created, not born.

One is not simply born a nerd; one must be made a nerd.

You cannot label someone a nerd because they do nerdy things; it’s an oversimplified assumption.

I do not do nerdy things because I am a nerd; rather, the nerdy things I do have warped my mind … making me a nerd.

Fedora 11 LiveCD Hangs on boot

Earlier today, I was attempting install Fedora 11 on a VMware virtual machine, but the boot process would hang with a black screen and a solid white curser at the top:



Fedora 11 LiveCD Hangs on Boot

After much whaling and gnashing of teeth, and a new download of the ISO because I thought it could be corrupted, I stumbled upon a quick fix.  Add the line “noapic acpi=off” to the boot options like this:

Fedora 11 LiveCD boot options

And voila, your LiveCD boots!

Fedora 11 LiveCD boots!

I recall having this issue on an old Dell notebook with a previous version of Fedora, but I couldn’t remember the options I used to get it to work.  Thanks to “dohnut” over here.

my mad design skills

I have two MAJOR pet peeves:

  • designers who think they’re developers, and
  • developers who think they’re designers

I understand that there are exceptions to the rule, but most people simply can’t wear both hats.

As you can tell, my color palette is immense and my stylish use of typeface is second to none.

Obviously, you can tell which category I fit into …

Lorem ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse fringilla ante auctor sem rutrum aliquet. Donec luctus gravida risus, at dictum erat condimentum id. Sed cursus orci pharetra est aliquam blandit. Suspendisse potenti. Curabitur tincidunt quam eu dolor viverra rhoncus. Morbi nulla turpis, ultrices pellentesque dictum et, accumsan in est. Proin nec mi augue. Suspendisse et nunc sed justo interdum aliquam. Nullam commodo volutpat risus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In rutrum sapien nec nulla feugiat sagittis a eget lorem. Mauris porttitor elit scelerisque sapien posuere fringilla.

Fusce tristique pulvinar vulputate. Curabitur vel leo velit. Pellentesque dolor sem, vestibulum non ornare nec, feugiat at augue. Aenean auctor, est ac consectetur mollis, ante purus placerat velit, ut semper orci lorem vehicula risus. Praesent pellentesque molestie ante eget viverra. Quisque a orci tortor. Cras in fermentum lorem. Nam convallis odio sed eros condimentum dignissim. Praesent tincidunt elit non justo sollicitudin id rutrum augue condimentum. Vestibulum et ante ante, nec pharetra ligula. Suspendisse sit amet purus in risus eleifend tempus. Cras auctor feugiat dui eu bibendum. Fusce vel ipsum leo, eu ultricies velit. Praesent eleifend euismod quam in mattis. Etiam risus nulla, viverra sed gravida ac, euismod dapibus arcu. Nulla pellentesque eleifend massa, at sodales augue ultrices et. Aliquam nec molestie sapien.