cancel
Showing results for 
Search instead for 
Did you mean: 

Generate random key for encryption module

Former Member
0 Kudos

Hi all,

I have defined a custom PI module for encrypt and decrypt fields in a xml,

For encrypt and decrypt the fields I'm using a varible=key array byte[], I need this varible is diferent in the several executions, for this reason I have the next code suurce where I asiggn a value to the variable Key with a random:

private  byte[] secretKey=new byte[8];

Random random= new Random();

random.setSeed(System.currentTimeMillis());

random.nextBytes(secretKey);

but the problem is that always have the same coding in the several executions,I dont understand where is the problem.

Thanks and best regards.

Mónica

Accepted Solutions (0)

Answers (1)

Answers (1)

iaki_vila
Active Contributor
0 Kudos

Hi Monica,

With System.currentTimeMillis() you would have different seed every time. I don't know if there is any problem to access to system variables, have you tried with the java.lang.Math method? coobird.net - How to Generate Random Numbers

Regards.

Former Member
0 Kudos

Hi Iñaki,

Yes, I generate the randon the diferente forms, for example?

//KeyGenerator generator;

//generator = KeyGenerator.getInstance("DES");

//generator.init(new SecureRandom());

//this.secretKey= generator.generateKey().getEncoded();

and ocurr the same problem...

I think is a problem with the memory, the memory not being released in the several executions.., and dont understand the reason, could is a problem in PI?

Thanks,

Monica

iaki_vila
Active Contributor
0 Kudos

Hi Monica,

At mapping level i think it is released. May be in adapter level, the adapter is running all the time and the memory is not released, although it seems to be weird. Have you tried to generate the random number from the mapping level and to take it in your new adapter as parameter?

Regards.

Former Member
0 Kudos

In the mapping level I can create the random number but the problem is that the first is execute the custom module and I think that If the random value is defined in the mapping level the field value before encrypt  could see in the monitoring no?

Regards,