// Generating a Secret Key

  // The DES algorithm requires a trusted source of random bits
  SecureRandom sr = new SecureRandom();

  // Create a KeyGenerator object for our algorithm of choice, DES
  KeyGenerator kg = KeyGenerator.getInstance( "DES" );
  kg.init( sr );

  // Generate the key
  SecretKey key = kg.generateKey();

  // Grab the raw bytes of the key
  byte rawKeyData[] = key.getEncoded();

  /* Now use the key to encrypt or decrypt, or save it in a file
     for later use. */
  doSomething( rawKeyData );