Version 5

    KeyGenerator service

     

    JBoss 3.2 added a UUID KeyGenerator service for developers needing unique key generation in their applications.   JBoss provides two key generation interfaces:

     

    • org.jboss.ejb.plugins.keygenerator.KeyGeneratorFactory: A factory for creating a key generator instance

    • org.jboss.ejb.plugins.keygenerator.KeyGenerator: A class which performs the actual key generation.

     

    JBoss also provides a UUID like key generator implementation in the org.jboss.ejb.plugins.keygenerator.uuid package.   Which generates 128 bit keys, encoded as 32 hex characters.  For example:  61E95D8BC0A80266002BCE4725E56141.

     

    Although it is possible to work with the UUID generator classes directly, doing so ties you to this specific implementation.  Instead, JBoss provides the UUID key generator factory in the JNDI tree under name UUIDKeyGeneratorFactory.  The following code can be used to locate the UUID key generator and generate a key:

     

       InitialContext ctx = new InitialContext();
       KeyGeneratorFactory kgf = (KeyGeneratorFactory) ctx.lookup("UUIDKeyGeneratorFactory");
       KeyGenerator kg = kgf.getKeyGenerator();
       Object uuid = kg.generateKey();