HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"J2ME Cryptography"
Vol. 6, Issue 7, p. 108

	


Listing 1

public void init( String password ) {
  byte[] toBeHashed = concat( getSalt(),
    password.getBytes() );
  byte[] hash = mSHA1.digest( toBeHashed );
  byte[] keyBytes = new byte[ 8 ];
  System.arraycopy( hash, 0, keyBytes, 0, 8 );
  mDES.setKey( keyBytes );
}


private byte[] encrypt( byte[] plaintext )
throws StorageException {
  try {
    byte[] iv = getRandomBytes( 8 );
    byte[] ciphertext = mDES.encrypt( plaintext,
      iv );
    return concat( iv, ciphertext );
  }
  catch( CipherException e ) {
    throw new StorageException( e.getMessage() );
  }
}



Listing 2

public PalmEncryptedStorage() {
  mDatabase = new Database( DB_TYPE_ID,
    CREATOR_ID, Database.READWRITE );
  if ( !mDatabase.isOpen() ) {
    Database.create( 0, DB_TYPE_STRING,
      CREATOR_ID, DB_TYPE_ID, false );
    mDatabase = new Database( DB_TYPE_ID,
      CREATOR_ID, Database.READWRITE );
    mDatabase.addRecord( getRandomBytes( 8 ) );
  }
}


private void setRecordBytes( int recordNumber,
  byte[] bytes ) {
  if ( mDatabase.getNumberOfRecords() <=
    recordNumber ) {
    mDatabase.addRecord( bytes );
  }
  else {
    mDatabase.setRecord( recordNumber, bytes );
  }
}



Listing 3

public void penDown( int x, int y ) {
  if ( mListBox.contains( x, y ) ) {
    mListBox.handlePenDown( x, y );
  }
  else if ( mNewButton.pressed( x, y ) ) {
    mPalmPassword.showSiteInfo( new SiteInfo() );
  }
}


public void penMove( int x, int y ) {
  if ( mListBox.contains( x, y ) ) {
    mListBox.handlePenMove( x, y );
  }
}

  
 
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.