| |
"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 );
}
}
|
|