01: package org.bouncycastle.crypto;
02:
03: import java.security.SecureRandom;
04:
05: /**
06: * The base class for symmetric, or secret, cipher key generators.
07: */
08: public class CipherKeyGenerator {
09: protected SecureRandom random;
10: protected int strength;
11:
12: /**
13: * initialise the key generator.
14: *
15: * @param param the parameters to be used for key generation
16: */
17: public void init(KeyGenerationParameters param) {
18: this .random = param.getRandom();
19: this .strength = (param.getStrength() + 7) / 8;
20: }
21:
22: /**
23: * generate a secret key.
24: *
25: * @return a byte array containing the key value.
26: */
27: public byte[] generateKey() {
28: byte[] key = new byte[strength];
29:
30: random.nextBytes(key);
31:
32: return key;
33: }
34: }
|