X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fbouncycastle%2Fcrypto%2FCipherKeyGenerator.java;fp=src%2Forg%2Fbouncycastle%2Fcrypto%2FCipherKeyGenerator.java;h=451f8e8f284a7f201d1cd714e845ccd84d45410f;hb=e5e9355b4f4e0e2c8de9068a71c1e3cc26fa9905;hp=0000000000000000000000000000000000000000;hpb=f35445729371789b3d496f426d7f87542f8e1a45;p=org.ibex.core.git diff --git a/src/org/bouncycastle/crypto/CipherKeyGenerator.java b/src/org/bouncycastle/crypto/CipherKeyGenerator.java new file mode 100644 index 0000000..451f8e8 --- /dev/null +++ b/src/org/bouncycastle/crypto/CipherKeyGenerator.java @@ -0,0 +1,38 @@ +package org.bouncycastle.crypto; + +import java.security.SecureRandom; + +/** + * The base class for symmetric, or secret, cipher key generators. + */ +public class CipherKeyGenerator +{ + protected SecureRandom random; + protected int strength; + + /** + * initialise the key generator. + * + * @param param the parameters to be used for key generation + */ + public void init( + KeyGenerationParameters param) + { + this.random = param.getRandom(); + this.strength = (param.getStrength() + 7) / 8; + } + + /** + * generate a secret key. + * + * @return a byte array containing the key value. + */ + public byte[] generateKey() + { + byte[] key = new byte[strength]; + + random.nextBytes(key); + + return key; + } +}