java.security.spec.RSAKeyGenParameterSpec#F4()源码实例Demo

下面列出了java.security.spec.RSAKeyGenParameterSpec#F4() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TencentKona-8   文件: SpecTest.java
public static void main(String[] args) throws Exception {

        int size = 0;

        if (args.length >= 1) {
            size = Integer.parseInt(args[0]);
        } else {
            throw new RuntimeException("Missing keysize to test with");
        }

        BigInteger publicExponent
                = (args.length >= 2) ? new BigInteger(args[1]) : RSAKeyGenParameterSpec.F4;

        System.out.println("Running test with key size: " + size
                + " and public exponent: " + publicExponent);

        KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
        kpg1.initialize(new RSAKeyGenParameterSpec(size, publicExponent));
        if (!specTest(kpg1.generateKeyPair(), publicExponent)) {
            throw new RuntimeException("Test failed.");
        }
    }
 
源代码2 项目: jdk8u_jdk   文件: SpecTest.java
public static void main(String[] args) throws Exception {

        int size = 0;

        if (args.length >= 1) {
            size = Integer.parseInt(args[0]);
        } else {
            throw new RuntimeException("Missing keysize to test with");
        }

        BigInteger publicExponent
                = (args.length >= 2) ? new BigInteger(args[1]) : RSAKeyGenParameterSpec.F4;

        System.out.println("Running test with key size: " + size
                + " and public exponent: " + publicExponent);

        KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
        kpg1.initialize(new RSAKeyGenParameterSpec(size, publicExponent));
        if (!specTest(kpg1.generateKeyPair(), publicExponent)) {
            throw new RuntimeException("Test failed.");
        }
    }
 
源代码3 项目: aion-germany   文件: KeyGen.java
/**
 * Initialize Key Generator (Blowfish keygen and RSA keygen)
 *
 * @throws GeneralSecurityException
 */
public static void init() throws GeneralSecurityException {
    log.info("Initializing Key Generator...");

    blowfishKeyGen = KeyGenerator.getInstance("Blowfish");

    KeyPairGenerator rsaKeyPairGenerator = KeyPairGenerator.getInstance("RSA");

    RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
    rsaKeyPairGenerator.initialize(spec);
    encryptedRSAKeyPairs = new EncryptedRSAKeyPair[10];

    for (int i = 0; i < 10; i++) {
        encryptedRSAKeyPairs[i] = new EncryptedRSAKeyPair(
                rsaKeyPairGenerator.generateKeyPair());
    }

    // Pre-init RSA cipher.. saving about 300ms
    Cipher rsaCipher = Cipher.getInstance("RSA/ECB/nopadding");
    rsaCipher.init(Cipher.DECRYPT_MODE, encryptedRSAKeyPairs[0].getRSAKeyPair().getPrivate());
}
 
源代码4 项目: openjdk-jdk8u   文件: SpecTest.java
public static void main(String[] args) throws Exception {

        int size = 0;

        if (args.length >= 1) {
            size = Integer.parseInt(args[0]);
        } else {
            throw new RuntimeException("Missing keysize to test with");
        }

        BigInteger publicExponent
                = (args.length >= 2) ? new BigInteger(args[1]) : RSAKeyGenParameterSpec.F4;

        System.out.println("Running test with key size: " + size
                + " and public exponent: " + publicExponent);

        KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
        kpg1.initialize(new RSAKeyGenParameterSpec(size, publicExponent));
        if (!specTest(kpg1.generateKeyPair(), publicExponent)) {
            throw new RuntimeException("Test failed.");
        }
    }
 
源代码5 项目: L2jBrasil   文件: LoginController.java
private LoginController() throws GeneralSecurityException
{
	_log.info("Loading LoginContoller...");

	_hackProtection = new HashMap<>();

	_keyPairs = new ScrambledKeyPair[10];

	KeyPairGenerator keygen = null;

	keygen = KeyPairGenerator.getInstance("RSA");
	RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
	keygen.initialize(spec);

	//generate the initial set of keys
	for (int i = 0; i < 10; i++)
	{
		_keyPairs[i] = new ScrambledKeyPair(keygen.generateKeyPair());
	}
	_log.info("Cached 10 KeyPairs for RSA communication");

	testCipher((RSAPrivateKey) _keyPairs[0]._pair.getPrivate());

	// Store keys for blowfish communication
	generateBlowFishKeys();
}
 
源代码6 项目: dragonwell8_jdk   文件: RSAKeyPairGenerator.java
public void initialize(int keySize, SecureRandom random) {

        // do not allow unreasonably small or large key sizes,
        // probably user error
        try {
            RSAKeyFactory.checkKeyLengths(keySize, RSAKeyGenParameterSpec.F4,
                512, 64 * 1024);
        } catch (InvalidKeyException e) {
            throw new InvalidParameterException(e.getMessage());
        }

        this.keySize = keySize;
        this.random = random;
        this.publicExponent = RSAKeyGenParameterSpec.F4;
    }
 
源代码7 项目: dragonwell8_jdk   文件: GenerateRSAKeyPair.java
public static void main(String[] args) throws Exception {

        RSAKeyGenParameterSpec rsaSpec =
        new RSAKeyGenParameterSpec (1024, RSAKeyGenParameterSpec.F4);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
        kpg.initialize(rsaSpec);

        // test generateKeyPair
        KeyPair kpair = kpg.generateKeyPair();
        if (kpair == null) {
            throw new Exception("no keypair generated");
        }
    }
 
源代码8 项目: openjdk-8-source   文件: RSAKeyPairGenerator.java
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
源代码9 项目: InviZible   文件: UpdateCheck.java
private KeyPair generateRSAKeyPair() throws Exception {
    SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
    RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
    KeyPairGenerator generator;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        generator = KeyPairGenerator.getInstance("RSA");
    } else {
        generator = KeyPairGenerator.getInstance("RSA", "BC");
    }
    generator.initialize(spec, secureRandom);
    return generator.generateKeyPair();
}
 
源代码10 项目: TencentKona-8   文件: RSAKeyPairGenerator.java
public void initialize(int keySize, SecureRandom random) {

        // do not allow unreasonably small or large key sizes,
        // probably user error
        try {
            RSAKeyFactory.checkKeyLengths(keySize, RSAKeyGenParameterSpec.F4,
                512, 64 * 1024);
        } catch (InvalidKeyException e) {
            throw new InvalidParameterException(e.getMessage());
        }

        this.keySize = keySize;
        this.random = random;
        this.publicExponent = RSAKeyGenParameterSpec.F4;
    }
 
源代码11 项目: jdk8u-dev-jdk   文件: RSAKeyPairGenerator.java
public void initialize(int keySize, SecureRandom random) {

        // do not allow unreasonably small or large key sizes,
        // probably user error
        try {
            RSAKeyFactory.checkKeyLengths(keySize, RSAKeyGenParameterSpec.F4,
                512, 64 * 1024);
        } catch (InvalidKeyException e) {
            throw new InvalidParameterException(e.getMessage());
        }

        this.keySize = keySize;
        this.random = random;
        this.publicExponent = RSAKeyGenParameterSpec.F4;
    }
 
源代码12 项目: jdk8u-jdk   文件: GenerateRSAKeyPair.java
public static void main(String[] args) throws Exception {

        RSAKeyGenParameterSpec rsaSpec =
        new RSAKeyGenParameterSpec (1024, RSAKeyGenParameterSpec.F4);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
        kpg.initialize(rsaSpec);

        // test generateKeyPair
        KeyPair kpair = kpg.generateKeyPair();
        if (kpair == null) {
            throw new Exception("no keypair generated");
        }
    }
 
源代码13 项目: L2jOrg   文件: AuthController.java
private void initializeScrambledKeys() throws GeneralSecurityException {
    var keygen = KeyPairGenerator.getInstance("RSA");
    var spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
    keygen.initialize(spec);

    _keyPairs = new ScrambledKeyPair[10];

    for (int i = 0; i < 10; i++) {
        _keyPairs[i] = new ScrambledKeyPair(keygen.generateKeyPair());
    }
    LOGGER.info("Cached 10 KeyPairs for RSA communication");

    testCipher((RSAPrivateKey) _keyPairs[0].getPair().getPrivate());
}
 
源代码14 项目: openjdk-8-source   文件: RSAKeyPairGenerator.java
public void initialize(int keySize, SecureRandom random) {

        // do not allow unreasonably small or large key sizes,
        // probably user error
        try {
            RSAKeyFactory.checkKeyLengths(keySize, RSAKeyGenParameterSpec.F4,
                512, 64 * 1024);
        } catch (InvalidKeyException e) {
            throw new InvalidParameterException(e.getMessage());
        }

        this.keySize = keySize;
        this.random = random;
        this.publicExponent = RSAKeyGenParameterSpec.F4;
    }
 
源代码15 项目: jdk8u60   文件: RSAKeyPairGenerator.java
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
源代码16 项目: jdk8u60   文件: GenerateRSAKeyPair.java
public static void main(String[] args) throws Exception {

        RSAKeyGenParameterSpec rsaSpec =
        new RSAKeyGenParameterSpec (1024, RSAKeyGenParameterSpec.F4);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
        kpg.initialize(rsaSpec);

        // test generateKeyPair
        KeyPair kpair = kpg.generateKeyPair();
        if (kpair == null) {
            throw new Exception("no keypair generated");
        }
    }
 
源代码17 项目: openjdk-jdk9   文件: GenerateRSAKeyPair.java
public static void main(String[] args) throws Exception {

        RSAKeyGenParameterSpec rsaSpec =
        new RSAKeyGenParameterSpec (1024, RSAKeyGenParameterSpec.F4);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
        kpg.initialize(rsaSpec);

        // test generateKeyPair
        KeyPair kpair = kpg.generateKeyPair();
        if (kpair == null) {
            throw new Exception("no keypair generated");
        }
    }
 
源代码18 项目: openjdk-jdk8u   文件: GenerateRSAKeyPair.java
public static void main(String[] args) throws Exception {

        RSAKeyGenParameterSpec rsaSpec =
        new RSAKeyGenParameterSpec (1024, RSAKeyGenParameterSpec.F4);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
        kpg.initialize(rsaSpec);

        // test generateKeyPair
        KeyPair kpair = kpg.generateKeyPair();
        if (kpair == null) {
            throw new Exception("no keypair generated");
        }
    }
 
源代码19 项目: jdk8u-dev-jdk   文件: GenerateRSAKeyPair.java
public static void main(String[] args) throws Exception {

        RSAKeyGenParameterSpec rsaSpec =
        new RSAKeyGenParameterSpec (1024, RSAKeyGenParameterSpec.F4);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
        kpg.initialize(rsaSpec);

        // test generateKeyPair
        KeyPair kpair = kpg.generateKeyPair();
        if (kpair == null) {
            throw new Exception("no keypair generated");
        }
    }
 
源代码20 项目: enmasse   文件: DeviceCertificateManager.java
@Override
public AlgorithmParameterSpec getSpec() {
    return new RSAKeyGenParameterSpec(2048, RSAKeyGenParameterSpec.F4);
}