/* * Copyright (C) 2011 Vex Software LLC * This file is part of Votifier. * * Votifier is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Votifier is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Votifier. If not, see <http://www.gnu.org/licenses/>. */ package com.vexsoftware.votifier.crypto; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.spec.RSAKeyGenParameterSpec; import java.util.logging.Logger; /** * An RSA key pair generator. * * @author Blake Beaupain */ public class RSAKeygen { /** The logger instance. */ private static final Logger LOG = Logger.getLogger("Votifier"); /** * Generates an RSA key pair. * * @param bits * The amount of bits * @return The key pair */ public static KeyPair generate(int bits) throws Exception { LOG.info("Votifier is generating an RSA key pair..."); KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA"); RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(bits, RSAKeyGenParameterSpec.F4); keygen.initialize(spec); return keygen.generateKeyPair(); } }