Database Reference
In-Depth Information
final methods, like final members, can be automatically compiled inline, which means the code or
value is included in the referrer byte code when compiled. This has some performance benefit, but that is
usually outweighed by the requirement to recompile if the final code ever changes.
The second effect of declaring our methods to be final is that they cannot be overridden by some
other class that implements our class. This is our primary reason for declaring methods in
OracleJavaSecure.java to be final . We are protecting our logic from being modified or spoofed. We
must abide the rule that our final methods may never change, or that the final methods are all private
so that we are the only one that refers to them. Continue with this thought in the following section.
Getting RSA Public Key Artifacts
You may have noticed in Listings 5-1 through 5-4 that all our keys and components thereof are declared
not only static , but also private . We do not give direct access to any of those. If you were very astute,
you might have also noticed that our methods so far were declared private : that is makeLocRSAKeys() ,
makeCryptUtilities() and makeExtRSAPubKey() are all private . We never expect our client applications,
nor our Java-stored procedures in Oracle to call these methods directly. We will define some public
methods that will call these private methods as needed.
The first two public methods that we will meet now are for getting the public RSA key artifacts. We
will ask client applications to call these methods shown in Listing 5-6.
Listing 5-6. Methods to Get Public Key Artifacts, getLocRSAPubMod() and getLocRSAPubExp()
private static BigInteger locRSAPubMod = null;
private static BigInteger locRSAPubExp;
public static final String getLocRSAPubMod() {
String rtrnString = "getLocRSAPubMod() failed";
try {
if ( null == locRSAPubMod ) makeLocRSAKeys();
rtrnString = locRSAPubMod.toString();
} catch ( Exception x ) {
x.printStackTrace();
}
return rtrnString;
}
public static final String getLocRSAPubExp() {
String rtrnString = "getLocRSAPubExp() failed";
try {
if ( null == locRSAPubMod ) makeLocRSAKeys();
rtrnString = locRSAPubExp.toString();
} catch ( Exception x ) {}
return rtrnString;
}
I'd like to point out several things in these public methods. First of all, notice that we test whether
locRSAPubMod is null . Recall that when we first declared locRSAPubMod (at top of this code) we set it to
null . (If we had declared it with this statement private static BigInteger locRSAPubMod , it would have
also been null , but because we put it into an if test, we would get a “might not have been initialized”
error when we try to compile.) If in the if test, locRSAPubMod is no longer null , then we must have already
created the RSA key pair. However, if it is still null , then we call the private method makeLocRSAKeys() .
 
Search WWH ::




Custom Search