code: public static void generateSecretKey(KeyConfig config)
  			throws NoSuchAlgorithmException, KeyStoreException,
  			CertificateException, IOException {
  
  		if (config == null || config.getKeyStoreFile() == null
  				|| StringUtils.isEmpty(config.getKeyEntryName())
  				|| config.getAlgorithm() == null) {
  			throw new KeyStoreException(
  					"Missing parameters, unable to create keystore.");
  		}
  
  		SecureRandom random = new SecureRandom();
  
  		KeyGenerator keygen = KeyGenerator.getInstance(config.getAlgorithm()
  				.getName(), new BouncyCastleProvider());
  		keygen.init(config.getKeySize(), random);
  
  		SecretKey key = keygen.generateKey();
  
  		KeyStore keyStore = KeyStore.getInstance("JCEKS");
  		FileInputStream fis = null;
  		if (config.getKeyStoreFile().exists()
  				&& FileUtils.sizeOf(config.getKeyStoreFile()) > 0) {
  			fis = new FileInputStream(config.getKeyStoreFile());
  		}
  
  		keyStore.load(fis, config.getKeyStorePassword().toCharArray());
  
  		KeyStore.ProtectionParameter protectionParameter = new KeyStore.PasswordProtection(
  				config.getKeyStorePassword().toCharArray());
  		KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(
  				key);
  
  		keyStore.setEntry(config.getKeyEntryName(), secretKeyEntry,
  				protectionParameter);
  		if (fis != null) {
  			fis.close();
  		}
  		FileOutputStream fos = new FileOutputStream(config.getKeyStoreFile());
  
  		keyStore.store(fos, config.getKeyStorePassword().toCharArray());
  
  		fos.close();
  
  	}
docs: Method which will generate a random Secret key and add it to a keystore
  with the entry name provided.
  
  @param config
  Configuration for generation of key.
  @throws NoSuchAlgorithmException
  @throws KeyStoreException
  @throws CertificateException
  @throws IOException