Database Reference
In-Depth Information
getting our client public key modulus and exponent, which in the process generates the RSA
Public/private key pair, if not existing.
Listing 6-19. Code for Client-Only Testing, from main()
String clientPubModulus = getLocRSAPubMod() ;
String clientPubExponent = getLocRSAPubExp() ;
// Emulates server actions
RAW mCryptSessionSecretDESPassPhrase =
getCryptSessionSecretDESPassPhrase( clientPubModulus,
clientPubExponent );
RAW mCryptSessionSecretDESSalt =
getCryptSessionSecretDESSalt( clientPubModulus,
clientPubExponent );
RAW mCryptSessionSecretDESAlgorithm =
getCryptSessionSecretDESAlgorithm( clientPubModulus,
clientPubExponent );
RAW mCryptSessionSecretDESIterationCount =
getCryptSessionSecretDESIterationCount( clientPubModulus,
clientPubExponent );
RAW cryptData = getCryptData ( "Monday" );
testAsClientAndServer = true ;
// As client
System.out.println( getDecryptData ( cryptData,
mCryptSessionSecretDESPassPhrase, mCryptSessionSecretDESAlgorithm,
mCryptSessionSecretDESSalt, mCryptSessionSecretDESIterationCount ) );
System.out.println( showAlgorithm () );
Next, we emulate the server, having received the modulus and exponent, getting the DES secret
password key artifacts from getCryptSessionSecretDESPassPhrase() and other methods. In the process,
a copy of the public key is built from the artifacts, the DES secret password key is generated and each of
the secret password key artifacts is encrypted using the RSA public key.
We also emulate the server, encrypting some data with the secret password key:
RAW cryptData = getCryptData( "Monday" );
Our next step in testing assumes we are back on the client, and having received all the encrypted
secret password key artifacts, we generate a copy of the secret password key from those artifacts. To do
that, we set testAsClientAndServer to be true in order to overwrite the secret password key that we just
created while emulating the server (even though the key will be identical):
testAsClientAndServer = true;
Now again as the client, we call getDecryptData() with all the DES secret password key artifacts, and
the encrypted data. This will create a new DES secret key based on the artifacts, then decrypt the data
using that key. We will print out the decrypted data, which should be the same as what we encrypted
earlier. Also, we will print out the DES algorithm name that we used for secret password encryption.
 
Search WWH ::




Custom Search