Database Reference
In-Depth Information
byte[] cryptBytes ;
cryptBytes = cryptSecretDESPassPhrase .getBytes() ;
sessionSecretDESPassPhraseChars =
byteArrayToCharArray ( cipherRSA.doFinal( cryptBytes ) );
cryptBytes = cryptSecretDESAlgorithm.getBytes();
sessionSecretDESAlgorithm = new String ( cipherRSA.doFinal( cryptBytes ) );
cryptBytes = cryptSecretDESSalt.getBytes();
salt = cipherRSA.doFinal( cryptBytes );
cryptBytes = cryptSecretDESIterationCount.getBytes();
iterationCount = cipherRSA.doFinal( cryptBytes ) [0] ;
//System.out.println( "\n" + new String( sessionSecretDESPassPhraseChars ) );
//System.out.println( sessionSecretDESAlgorithm );
//System.out.println( new String( salt ) );
//System.out.println( iterationCount );
}
For each artifact, we convert the encrypted RAW into a byte array and pass it to the cipherRSA
member to be decrypted. We use the byte array coming back from the Cipher to populate our static class
members with an appropriate data type. Keep the value as a byte array for salt , char array for
sessionSecretDESPassPhraseChars by calling the byteArrayToCharArray() method, String for
sessionSecretDESAlgorithm by instantiating a new String() , and a single byte , automatically cast as an
int for iterationCount .
If you are interested in observing these session-specific, random artifacts and the negotiated
algorithm as they arrive at the client, you can uncomment the System.out.println() calls at the end of
the method. However, you should only do this temporarily: the System.out.println() calls have been
removed from the code in the next chapter.
Ancillary Methods for Array Conversion
In two places in the preceding code, we called some ancillary array conversion methods that we have
defined in the OracleJavaSecure code, shown in Listing 6-17. One takes a byte array and converts it to a
char array. The other does the opposite. We call byteArrayToCharArray() from
decryptSessionSecretDESPassPhrase() (see Listing 6-16) when we get
sessionSecretDESPassPhraseChars , and we call charArrayToByteArray() from
getCryptSessionSecretDESPassPhrase() (see Listing 6-5) when we are encrypting
sessionSecretDESPassPhraseChars .
Listing 6-17. Array Conversion Methods, byteArrayToCharArray() and charArrayToByteArray()
static char[] byteArrayToCharArray( byte[] bytes ) {
char[] rtrnArray = new char[bytes.length];
for ( int i = 0; i < bytes.length; i++ ) {
rtrnArray[i] = ( char )bytes[i];
}
return rtrnArray;
}
static byte[] charArrayToByteArray( char[] chars ) {
byte[] rtrnArray = new byte[chars.length];
for ( int i = 0; i < chars.length; i++ ) {
rtrnArray[i] = ( byte )chars[i];
 
Search WWH ::




Custom Search