當前位置: 首頁>>代碼示例>>Java>>正文


Java RSAKeyGenParameterSpec.F4屬性代碼示例

本文整理匯總了Java中java.security.spec.RSAKeyGenParameterSpec.F4屬性的典型用法代碼示例。如果您正苦於以下問題:Java RSAKeyGenParameterSpec.F4屬性的具體用法?Java RSAKeyGenParameterSpec.F4怎麽用?Java RSAKeyGenParameterSpec.F4使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在java.security.spec.RSAKeyGenParameterSpec的用法示例。


在下文中一共展示了RSAKeyGenParameterSpec.F4屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: LoginController

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();
}
 
開發者ID:L2jBrasil,項目名稱:L2jBrasil,代碼行數:26,代碼來源:LoginController.java

示例2: generateRSAKeypair

public static KeyPair generateRSAKeypair(int keysize, BigInteger publicExponent,
        SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException,
        InvalidAlgorithmParameterException {
    BigInteger tmpPublicExponent = publicExponent;
    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    }
    AlgorithmParameterSpec params = new RSAKeyGenParameterSpec(keysize, tmpPublicExponent);
    KeyPairGenerator kpGen = getKeyPairGenerator("RSA");
    synchronized (kpGen) {
        if (random == null) {
            kpGen.initialize(params);
        } else {
            kpGen.initialize(params, random);
        }
        return kpGen.generateKeyPair();
    }
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:18,代碼來源:KeyUtil.java

示例3: main

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.");
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:SpecTest.java

示例4: CertRASession

public CertRASession(String emailPrivate, String phonePrivate) throws Exception {
	KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
	RSAKeyGenParameterSpec params = new RSAKeyGenParameterSpec(2048, RSAKeyGenParameterSpec.F4);

	SecureRandom secureRandom = new SecureRandom();
	secureRandom.setSeed(System.currentTimeMillis());

	keyPairGenerator.initialize(params, secureRandom);
	KeyPair keyPair = keyPairGenerator.genKeyPair();

	this.privateKey = keyPair.getPrivate();
	this.publicKey = keyPair.getPublic();

	this.emailPrivate = emailPrivate;
	this.phonePrivate = phonePrivate;
}
 
開發者ID:e-Contract,項目名稱:mycarenet,代碼行數:16,代碼來源:CertRASession.java

示例5: genKeys

private void genKeys(int keyLength, String folderName) {
    if (keyLength > 0)
        this.keyLength = keyLength;
    if (folderName != null)
        this.folderName = folderName;
    if (!this.folderName.endsWith("/"))
        this.folderName += "/";
    System.out.printf("Generating %d-bit RSA keys in folder '%s'\n", this.keyLength, this.folderName);
    try {
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");

        // Generate a key that is keyLength bits long
        RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(this.keyLength, RSAKeyGenParameterSpec.F4);
        keyGen.initialize(spec);
        KeyPair pair = keyGen.generateKeyPair();
        printKeyPair(pair);
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
開發者ID:moparisthebest,項目名稱:MoparScape,代碼行數:21,代碼來源:KeyGenerator.java

示例6: loadRSAKeys

private void loadRSAKeys() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
{
	KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
	RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(512,RSAKeyGenParameterSpec.F4);
	keyGen.initialize(spec);

	_keyPairs = new KeyPair[KEYS_SIZE];
	for (int i = 0; i < KEYS_SIZE; i++)
	{
		_keyPairs[i] = keyGen.genKeyPair();
	}
}
 
開發者ID:L2jBrasil,項目名稱:L2jBrasil,代碼行數:12,代碼來源:GameServerTable.java

示例7: LoginController

private LoginController() throws GeneralSecurityException
{
	_log.info("Loading LoginController...");
	
	_keyPairs = new ScrambledKeyPair[10];
	
	final KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
	
	final 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();
	
	final Thread purge = new PurgeThread();
	purge.setDaemon(true);
	purge.start();
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:27,代碼來源:LoginController.java

示例8: initialize

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;
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:15,代碼來源:RSAKeyPairGenerator.java

示例9: main

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");
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:13,代碼來源:GenerateRSAKeyPair.java

示例10: generate

/**
 * Generates an RSA key pair.
 *
 * @param bits The amount of bits
 * @return The key pair
 */
public static KeyPair generate(int bits) throws Exception {
    KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
    RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(bits,
            RSAKeyGenParameterSpec.F4);
    keygen.initialize(spec);
    return keygen.generateKeyPair();
}
 
開發者ID:NuVotifier,項目名稱:NuVotifier,代碼行數:13,代碼來源:RSAKeygen.java

示例11: generateKeyPair

/**
 * Generates a new 2014-bit RSA key pair.
 * @return A new RSA key pair or null on error.
 */
public static KeyPair generateKeyPair() {
    // Generate key pair for 1024-bit RSA encryption and decryption
    try {
        SecureRandom random = new SecureRandom();
        RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
        KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
        generator.initialize(spec, random);
        return generator.genKeyPair();
    } catch (Exception e) {
        Log.e("HomeStuff", "RSA key pair error" + e);
        return null;
    }
}
 
開發者ID:DanDits,項目名稱:WhatsThat,代碼行數:17,代碼來源:SimpleCrypto.java

示例12: LoginController

private LoginController() throws GeneralSecurityException
{
	_log.info("Loading LoginController...");
	
	_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();
	
	Thread purge = new PurgeThread();
	purge.setDaemon(true);
	purge.start();
}
 
開發者ID:Zoey76,項目名稱:L2J_LoginServer,代碼行數:28,代碼來源:LoginController.java

示例13: main

@Override
public void main(Provider p) throws Exception {
    long start = System.currentTimeMillis();
    provider = p;
    data = new byte[2048];
    // keypair generation is very slow, test only a few short keys
    int[] keyLengths = {512, 512, 1024};
    BigInteger[] pubExps = {null, RSAKeyGenParameterSpec.F4, null};
    KeyPair[] keyPairs = new KeyPair[3];
    RandomFactory.getRandom().nextBytes(data);
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", provider);
    for (int i = 0; i < keyLengths.length; i++) {
        int len = keyLengths[i];
        BigInteger exp = pubExps[i];
        System.out.println("Generating " + len + " bit keypair...");
        if (exp == null) {
            kpg.initialize(len);
        } else {
            kpg.initialize(new RSAKeyGenParameterSpec(len, exp));
        }
        KeyPair kp = kpg.generateKeyPair();
        keyPairs[i] = kp;
        RSAPublicKey publicKey = (RSAPublicKey)kp.getPublic();
        System.out.println(publicKey);
        RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey)kp.getPrivate();
        if (publicKey.getModulus().equals(privateKey.getModulus()) == false) {
            throw new Exception("Moduli do not match");
        }
        if (publicKey.getPublicExponent().equals(privateKey.getPublicExponent()) == false) {
            throw new Exception("Exponents do not match");
        }
        int keyLen = publicKey.getModulus().bitLength();
        if ((keyLen > len) || (keyLen < len - 1)) {
            throw new Exception("Incorrect key length: " + keyLen);
        }
        if (exp != null) {
            if (exp.equals(publicKey.getPublicExponent()) == false) {
                throw new Exception("Incorrect exponent");
            }
        }
        test(privateKey, publicKey);
    }
    testInvalidSignature(keyPairs[0], keyPairs[1]);
    testInvalidSignature(keyPairs[0], keyPairs[2]);
    long stop = System.currentTimeMillis();
    System.out.println("All tests passed (" + (stop - start) + " ms).");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:47,代碼來源:TestKeyPairGenerator.java


注:本文中的java.security.spec.RSAKeyGenParameterSpec.F4屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。