Database Reference
In-Depth Information
private static BigInteger locRSAPubExp;
locRSAPubMod = locRSAPubKey.getModulus();
locRSAPubExp = locRSAPubKey.getPublicExponent();
The methods getModulus() and getPublicExponent() are available in the RSAPublicKey class, but not
in the PublicKey class. We cast the PublicKey as an RSAPublicKey in order to use these methods (see
previous section). In essence, we ask the RSA public key to give us the value of its modulus and
exponent.
These numeric values are too large to handle without wrapping them in Java objects. We get them as
BigInteger objects. They can be very large numbers (especially the modulus) that don't fit well into
standard primitive types like integers or longs , and for that reason, we often handle and transmit these
numbers as if they were Strings .
You might have noticed that we declared locRSAPubMod to be null . You will recall our reasons for this
from the section called “Declaring and Initializing Members” in Chapter 4. In this case, we plan to test
whether locRSAPubMod is null to see if we need to generate the keys or if they already exist.
Serialize Objects
We are not limited to transmitting only simple type values to and from Oracle database. In Oracle, we
can define new types that hold arrays or data structures, and we can transmit objects in RAW format (an
ordered sequence of bytes). If we want to transmit very large objects, we can transmit and store them as
binary large objects ( BLOB s) in Oracle.
There is one requirement for transmitting a Java object across the network, and for storing a Java
object, for that matter; that is, the Java object must implement the Serializable interface. Normally, an
interface is a set of members and methods that must be implemented (set in code) by any class that
implements the interface. (We will create our own interface in Chapter 10.) However, with the
Serializable interface, there are no members or methods to be implemented; rather, implementing the
interface just indicates that you intend to package an instance of your class for transmission or storage.
You can send an object that is Serializable across an ObjectStream or write it to a File with an
ObjectWriter class.
Some objects cannot be serialized (cannot implement Serializable ). If something about the state of
an object exists by association rather than as a value, then the object cannot be serialized. For example,
if our object has an Oracle Connection member, then the connection cannot be serialized (you can't save
a connection for use later), and our object cannot be serialized.
Building the Public Key from Artifacts
On the other side of the encryption/decryption process, we want to get the necessary artifacts
(components) of the public key, and we want to rebuild the key. We are going to look at how we transmit
the components from the client to the server in just a minute, but for this discussion and for testing, we
can simply get them locally and build the key (we will use the same code on the server side). Listing 5-3
shows the code to build the public key from components of the key.
 
Search WWH ::




Custom Search