mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Merge branch 'master' of https://atomicint@bitbucket.org/Major-/apollo.git
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package org.apollo.tools;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* An RSA key generator.
|
||||
*
|
||||
* @author Graham
|
||||
* @author Major
|
||||
*/
|
||||
public final class RsaKeyGenerator {
|
||||
|
||||
/**
|
||||
* The bit count. <strong>Strongly</strong> recommended to be at least 2,048.
|
||||
*/
|
||||
private static final int BIT_COUNT = 2_048;
|
||||
|
||||
/**
|
||||
* The entry point of the RsaKeyGenerator.
|
||||
*
|
||||
* @param args The application arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Random random = new SecureRandom();
|
||||
|
||||
BigInteger publicKey = BigInteger.valueOf(65_537);
|
||||
BigInteger p, q, phi, modulus, privateKey;
|
||||
|
||||
do {
|
||||
p = BigInteger.probablePrime(BIT_COUNT / 2, random);
|
||||
q = BigInteger.probablePrime(BIT_COUNT / 2, random);
|
||||
phi = (p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE));
|
||||
|
||||
modulus = p.multiply(q);
|
||||
privateKey = publicKey.modInverse(phi);
|
||||
} while (modulus.bitLength() != BIT_COUNT || privateKey.bitLength() != BIT_COUNT
|
||||
|| !phi.gcd(publicKey).equals(BigInteger.ONE));
|
||||
|
||||
System.out.println("modulus: " + modulus);
|
||||
System.out.println("public key: " + publicKey);
|
||||
System.out.println("private key: " + privateKey);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user