Home > |
---|
You may prefer to dynamically register the SafeNet provider in order to avoid possible negative impacts on other applications running on the same machine. Using dynamic registration also allows you to keep installation as straightforward as possible for your customers.
This sample code shows an example of dynamic registration with SafeNet's SafeNet provider. The SafeNet provider is registered in position 2, ensuring that the "SUN" provider is still the default. If you want the SafeNet provider to be used when no provider is explicitly specified, it should be registered at position 1.
try {
com.safenetinc.luna.LunaSlotManager.getInstance().login("<HSM Partition Password>");
java.security.Provider provider = new com.safenetinc.luna.provider.LunaProvider();
// removing the provider is only necessary if it is already registered
// and you want to change its position
java.security.Security.removeProvider(provider.getName());
java.security.Security.insertProviderAt(provider, 2);
com.safenetinc.luna.LunaSlotManager.getInstance().logout();
} catch (Exception e) {
System.out.println("Exception caught during loading of the providers: "
+ ex.getMessage());
}