<commit_before>//$Id: KeyStoreGenerator.java,v 1.1 2004/08/07 13:54:04 steview Exp $

package org.jgroups.demos;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.security.KeyStore;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

/**
 * Generates a keystore file that has a SecretKey in it. It is not possible to 
 * use the keytool JDk tool to achieve this. This is a simple way to generate 
 * a JCEKS format keystore and SecretKey.
 * 
 * Usage is --alg ALGNAME --size ALGSIZE --storeName FILENAME --storePass PASSWORD --alias KEYALIAS
 * 
 * Any of args are optional and will default to
 * <ul>
 * <li>ALGNAME = Blowfish 
 * <li>ALGSIZE = 56
 * <li>FILENAME = defaultStore.keystore
 * <li>PASSWORD = <PASSWORD>
 * <li>ALIAS = mykey
 * </ul>
 * 
 * @author <NAME>
 *
 */
public class KeyStoreGenerator {

	static String symAlg = "Blowfish";
	static int keySize =56;
	static String keyStoreName = "defaultStore.keystore";
	static String storePass = "<PASSWORD>";
	static String alias = "myKey";
	
	public static void main(String[] args)
	{
		
		int i = 0, j;
        String arg =null;;
        boolean specified =false;
        
		 while (i < args.length && args[i].startsWith("-")) {
            arg = args[i++];

            if (arg.equalsIgnoreCase("--alg")){
            	if (i<args.length){
            		symAlg = args[i++];
            	}else{
            		System.out.println("No Algorithm supplied using default of "+ symAlg);
            	}
            }
            else if (arg.equalsIgnoreCase("--size")){
            	if (i<args.length){
            		keySize = Integer.parseInt(args[i++]);
            	}else{
            		System.out.println("No Size supplied using default of "+keySize);
            	}
            }else if (arg.equalsIgnoreCase("--storeName")){
            	if (i<args.length){
            		keyStoreName = args[i++];
            	}else{
            		System.out.println("No Size supplied using default of "+keyStoreName);
            	}
            }
            else if (arg.equalsIgnoreCase("--storePass")){
            	if (i<args.length){
            		storePass = args[i++];
            	}else{
            		System.out.println("No password supplied using default of "+storePass);
            	}
            }
            else if (arg.equalsIgnoreCase("--alias")){
            	if (i<args.length){
            		alias = args[i++];
            	}else{
            		System.out.println("No alias supplied using default of "+alias);
            	}
            }
            }
		 System.out.println("Creating file '" + keyStoreName +"' using Algorithm '"+ 
		 		symAlg +"' size '"+keySize + "'");
		 
		 OutputStream stream =null;
		 try {
		 stream= new FileOutputStream(keyStoreName);
		 SecretKey key = initSymKey();
		 KeyStore store = KeyStore.getInstance("JCEKS");
		 store.load(null,null);
		 store.setKeyEntry(alias,key,storePass.toCharArray(),null);<commit_msg>updated generator for correct arg parsing<commit_after>//$Id: KeyStoreGenerator.java,v 1.2 2005/01/07 15:15:26 steview Exp $

package org.jgroups.demos;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.security.KeyStore;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

/**
 * Generates a keystore file that has a SecretKey in it. It is not possible to 
 * use the keytool JDk tool to achieve this. This is a simple way to generate 
 * a JCEKS format keystore and SecretKey.
 * 
 * Usage is --alg ALGNAME --size ALGSIZE --storeName FILENAME --storePass PASSWORD --alias KEYALIAS
 * 
 * Any of args are optional and will default to
 * <ul>
 * <li>ALGNAME = Blowfish 
 * <li>ALGSIZE = 56
 * <li>FILENAME = defaultStore.keystore
 * <li>PASSWORD = <PASSWORD>
 * <li>ALIAS = mykey
 * </ul>
 * 
 * @author <NAME>
 *
 */
public class KeyStoreGenerator {

	static String symAlg = "Blowfish";
	static int keySize =56;
	static String keyStoreName = "defaultStore.keystore";
	static String storePass = "<PASSWORD>";
	static String alias = "myKey";
	
	public static void main(String[] args)
	{
		
		int i = 0, j;
        String arg =null;;
        boolean specified =false;
        
		 while (i < args.length && args[i].startsWith("-")) {
            arg = args[i++];
            System.out.println("Found arg of " + arg);
            if (arg.equalsIgnoreCase("--alg")){
            	if (i<args.length){
            		symAlg = args[i++];
            	}else{
            		System.out.println("No Algorithm supplied using default of "+ symAlg);
            	}
            }
            else if (arg.equalsIgnoreCase("--size")){
            	if (i<args.length){
            		keySize = Integer.parseInt(args[i++]);
            	}else{
            		System.out.println("No Size supplied using default of "+keySize);
            	}
            }else if (arg.equalsIgnoreCase("--storeName")){
                
            	if (i<args.length){
            	    String temp = args[i++];
            		keyStoreName = temp;
            	}else{
            		System.out.println("No keystore supplied using default of "+keyStoreName);
            	}
            }
            else if (arg.equalsIgnoreCase("--storePass")){
            	if (i<args.length){
            		storePass = args[i++];
            	}else{
            		System.out.println("No password supplied using default of "+storePass);
            	}
            }
            else if (arg.equalsIgnoreCase("--alias")){
            	if (i<args.length){
            		alias = args[i++];
            	}else{
            		System.out.println("No alias supplied using default of "+alias);
            	}
            }
            }
		 System.out.println("Creating file '" + keyStoreName +"' using Algorithm '"+ 
		 		symAlg +"' size '"+keySize + "'");
		 
		 OutputStream stream =null;
		 try {
		 stream= new FileOutputStream(keyStoreName);
		 SecretKey key = initSymKey();
		 KeyStore store = KeyStore.getInstance("JCEKS");
		 store.load(null,null);
		 store.setKeyEntry(alias,key,storePass.toCharArray(),null);
{'fraction_non_alphanumeric': 0.12640635340833886, 'fraction_numerical': 0.006949040370615486, 'mean_word_length': 2.107969151670951, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5002432', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1804, 'n_words': 473}