Database Reference
In-Depth Information
rtrnRAW = getRSACryptData( extRSAPubMod, extRSAPubExp, salt );
} catch( Exception x ) {}
return rtrnRAW;
}
Listing 6-8.
Encrypt the Itteration Count,
getCryptSessionSecretDESIterationCount ()
public static final RAW getCryptSessionSecretDESIterationCount(
String extRSAPubMod, String extRSAPubExp )
{
RAW rtrnRAW =
new RAW( "getCryptSessionSecretDESIterationCount() failed".getBytes() );
try {
if( null == sessionSecretDESKey ) makeSessionSecretDESKey();
byte[] sessionSecretDESIterationCountBytes =
{ ( byte )iterationCount };
rtrnRAW = getRSACryptData( extRSAPubMod, extRSAPubExp,
sessionSecretDESIterationCountBytes );
} catch( Exception x ) {}
return rtrnRAW;
}
This last method for returning the encrypted iteration count creates a byte array of one
byte
. The
only
byte
in the array is the iteration count
int
, cast as a
byte
. In that way, we can call the same method
to encrypt the iteration count as a byte array. We will have to reverse that process when we decrypt it at
the client.
Encrypting Data with Our Secret Password
We will call the same method on both the client and Oracle database to encrypt data using the secret
password key. The syntax, in Listing 6-9, should be familiar by now. This method takes a
String
of clear
text data and returns a
RAW
of encrypted data. Notice that initializing the
Cipher
using the
sessionSecretDESKey
is very similar to how we do it with the RSA keys, except that we also provide the
paramSpec
.
Listing 6-9.
Encrypt Data with Secret Password,
getCryptData()
public static final RAW getCryptData( String clearData ) {
if( null == clearData ) return null;
RAW rtrnRAW = new RAW( "getCryptData() failed".getBytes() );
try {
if( null == sessionSecretDESKey ) makeSessionSecretDESKey();
cipherDES.init( Cipher.ENCRYPT_MODE, sessionSecretDESKey, paramSpec )
;
rtrnRAW = new RAW( cipherDES.doFinal( clearData.getBytes() ) );
} catch( Exception x ) {}
return rtrnRAW;
}
Like the methods we described earlier for encrypting and returning our secret password key
artifacts, this method tests whether the
sessionSecretDESKey
has been instantiated, and attempts to
create it if not. This is good practice on the Oracle database, but is presumptuous on the client (where