Announcement Announcement Module
Collapse
No announcement yet.
Query about KeyGenerators Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Query about KeyGenerators

    Hello techsters -

    I have a requirement wherein, in my application I want to facilitate creation of random numbers by one set of users who will then hand it over to other set of users. So for example a user A will want to create a key and give it to user B. User B will then use this key as a medium to look at some information being saved by user A at some other point of time. Hence it becomes mandatory to save the key that was generated by user A in the database. With the fact the key needs to be random and stored in the database the following is what I have thought as for the implementation:

    My spring config file has the following bean definitions :

    <bean id = "bytesKeyGenerator" class = "org.springframework.security.crypto.keygen.KeyGen erators"
    factory-method="secureRandom">
    <constructor-arg type="int" value="4"/>
    </bean>

    <bean id = "stringKeyGenerator" class =
    "org.springframework.security.crypto.keygen.HexEnc odingStringKeyGenerator">
    <constructor-arg ref="bytesKeyGenerator"></constructor-arg>
    </bean>

    In the application when the key needs to be generated, I would then get hold of the "stringKeyGenerator" bean and call its generateKey() method to generate the key. I would then set this key on a new instance of a custom class (for which there corresponds a table using JPA ) and store this custom object in the database These kind of keys will be generated very often. There is also a uniqueness constraint on the key column in this table that holds the custom object, here is a snapshot of the custom class.

    @Entity
    @Table(uniqueConstraints = @UniqueConstraint(columnNames = { "code" }))
    public class CustomClass{

    @NotNull
    @Column(nullable=false)
    private String code;

    }

    My question is - Would there be a chance of collision for the code value ? Is this a good way to implement ?
    Any better suggestions would be really appreciated, If there is anything that the spring framework can help please do let me know.

    Best Regards.
Working...
X