/******************************************************************************* * Copyright (c) 2015 Kaloyan Raev. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Kaloyan Raev - initial API and implementation *******************************************************************************/ package signature; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.PrivateKey; import java.security.PublicKey; import java.security.SecureRandom; public class GenKeys { public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("Usage: GenKey nameOfFile"); System.exit(1); } KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN"); SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN"); keyGen.initialize(1024, random); KeyPair pair = keyGen.generateKeyPair(); PrivateKey priv = pair.getPrivate(); PublicKey pub = pair.getPublic(); Utils.saveKeyToFile(priv, args[0]); Utils.saveKeyToFile(pub, args[0] + ".pub"); } }