当前位置: 首页>>代码示例>>Java>>正文


Java RSAKeyGenParameterSpec类代码示例

本文整理汇总了Java中java.security.spec.RSAKeyGenParameterSpec的典型用法代码示例。如果您正苦于以下问题:Java RSAKeyGenParameterSpec类的具体用法?Java RSAKeyGenParameterSpec怎么用?Java RSAKeyGenParameterSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RSAKeyGenParameterSpec类属于java.security.spec包,在下文中一共展示了RSAKeyGenParameterSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: LoginController

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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,代码行数:27,代码来源:LoginController.java

示例2: initialize

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
        rsaParams.getPublicExponent(),
        random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:18,代码来源:KeyPairGeneratorSpi.java

示例3: generateRSAKeypair

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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,代码行数:19,代码来源:KeyUtil.java

示例4: createKeysM

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
static void createKeysM(String alias, boolean requireAuth) {
    try {
        KeyPairGenerator keyPairGenerator =
                KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA,
                        SecurityConstants.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);
        keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(alias,
                KeyProperties.PURPOSE_ENCRYPT
                        | KeyProperties.PURPOSE_DECRYPT).setAlgorithmParameterSpec(
                new RSAKeyGenParameterSpec(1024, F4))
                .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
                .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
                .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA384,
                        KeyProperties.DIGEST_SHA512)
                // Only permit the private key to be used if the user authenticated
                // within the last five minutes.
                .setUserAuthenticationRequired(requireAuth)
                .build());
        KeyPair keyPair = keyPairGenerator.generateKeyPair();
        Log.d(TAG, "Public Key is: " + keyPair.getPublic().toString());
    } catch (NoSuchProviderException | NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:ronghao,项目名称:CacheManage,代码行数:25,代码来源:KeyStoreHelper.java

示例5: initRSAKeys

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
/**
 * Inits the RSA keys.
 */
private void initRSAKeys()
{
	try
	{
		final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
		keyGen.initialize(new RSAKeyGenParameterSpec(512, RSAKeyGenParameterSpec.F4));
		_keyPairs = new KeyPair[KEYS_SIZE];
		for (int i = 0; i < KEYS_SIZE; i++)
		{
			_keyPairs[i] = keyGen.genKeyPair();
		}
	}
	catch (Exception e)
	{
		LOGGER.severe(GameServerTable.class.getSimpleName() + ": Error loading RSA keys for Game Server communication!");
	}
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:21,代码来源:GameServerTable.java

示例6: main

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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,代码行数:23,代码来源:SpecTest.java

示例7: createKeysM

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private static void createKeysM(String alias, boolean requireAuth)
    throws NoSuchProviderException, NoSuchAlgorithmException,
    InvalidAlgorithmParameterException {
    KeyPairGenerator keyPairGenerator =
        KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA,
            SecurityConstants.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);
    keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(alias,
        KeyProperties.PURPOSE_ENCRYPT
            | KeyProperties.PURPOSE_DECRYPT).setAlgorithmParameterSpec(
        new RSAKeyGenParameterSpec(1024, F4))
        .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
        .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
        .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA384,
            KeyProperties.DIGEST_SHA512)
        // Only permit the private key to be used if the user authenticated
        // within the last five minutes.
        .setUserAuthenticationRequired(requireAuth)
        .build());
    KeyPair keyPair = keyPairGenerator.generateKeyPair();
    Log.d(TAG, "Public Key is: " + keyPair.getPublic().toString());
}
 
开发者ID:plusend,项目名称:DiyCode,代码行数:23,代码来源:KeyStoreHelper.java

示例8: initialize

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
@Override
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {
    if (!(params instanceof RSAKeyGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException("Only RSAKeyGenParameterSpec supported");
    }

    RSAKeyGenParameterSpec spec = (RSAKeyGenParameterSpec) params;

    final BigInteger publicExponent = spec.getPublicExponent();
    if (publicExponent != null) {
        this.publicExponent = publicExponent.toByteArray();
    }

    this.modulusBits = spec.getKeysize();
}
 
开发者ID:google,项目名称:conscrypt,代码行数:17,代码来源:OpenSSLRSAKeyPairGenerator.java

示例9: initialize

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
  HashMap attributes = new HashMap();
  if (params != null)
    {
      if (! (params instanceof RSAKeyGenParameterSpec))
        throw new InvalidAlgorithmParameterException("params");

      attributes.put(RSAKeyPairGenerator.RSA_PARAMETERS, params);
    }
  if (random != null)
    attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);

  attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
                 Integer.valueOf(Registry.ASN1_ENCODING_ID));
  adaptee.setup(attributes);
}
 
开发者ID:vilie,项目名称:javify,代码行数:19,代码来源:RSAKeyPairGeneratorSpi.java

示例10: CertRASession

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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,代码行数:17,代码来源:CertRASession.java

示例11: test

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
@Test
public void test() throws Exception {
    // install BouncyCastle provider
    Security.addProvider(new BouncyCastleProvider());

    // generate a keypair
    KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA", "BC");
    RSAKeyGenParameterSpec params = new RSAKeyGenParameterSpec(STRENGTH, PUBLIC_EXP);
    gen.initialize(params, new SecureRandom());
    KeyPair keyPair = gen.generateKeyPair();

    FSTConfiguration fst = FSTConfiguration.createDefaultConfiguration();

    // serialize
    byte[] serialized = fst.asByteArray(keyPair);

    // deserialize --> crash
    KeyPair deserialized = (KeyPair) fst.asObject(serialized);
}
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:20,代码来源:I52.java

示例12: initialize

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
public void initialize(
    AlgorithmParameterSpec  params,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec     rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
                    rsaParams.getPublicExponent(),
                    random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
 
开发者ID:bullda,项目名称:DroidText,代码行数:18,代码来源:JDKKeyPairGenerator.java

示例13: genKeys

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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,代码行数:22,代码来源:KeyGenerator.java

示例14: loadRSAKeys

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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,代码行数:13,代码来源:GameServerTable.java

示例15: setup

import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
/**
 * Setup the test.
 */
@BeforeClass
public static void setup() throws Exception {
  Provider bc = new BouncyCastleProvider();
  Security.addProvider(bc);

  final byte[] preimage = "Hello World!".getBytes(Charset.defaultCharset());
  final byte[] prefix = "Ying ".getBytes(Charset.defaultCharset());
  final byte[] message = "Yang".getBytes(Charset.defaultCharset());
  //final byte[] prefixedMessage = "Ying Yang".getBytes(Charset.defaultCharset());

  final MessageDigest sha256Digest = MessageDigest.getInstance("SHA-256");
  final MessageDigest sha512Digest = MessageDigest.getInstance("SHA-512");

  //final byte[] fingerprint = sha256Digest.digest(preimage);

  final KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
  rsaKpg.initialize(new RSAKeyGenParameterSpec(2048, new BigInteger("65537")));
  KeyPair rsaKeyPair = rsaKpg.generateKeyPair();
  Signature rsaSigner = Signature.getInstance("SHA256withRSA/PSS");
  rsaSigner.initSign(rsaKeyPair.getPrivate());
  rsaSigner.update(message);

  net.i2p.crypto.eddsa.KeyPairGenerator edDsaKpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
  KeyPair edDsaKeyPair = edDsaKpg.generateKeyPair();
  Signature edDsaSigner = new EdDSAEngine(sha512Digest);
  edDsaSigner.initSign(edDsaKeyPair.getPrivate());
  edDsaSigner.update(prefix);
  edDsaSigner.update(message);

  preimageCondition = new PreimageSha256Condition(preimage);
  rsaCondition = new RsaSha256Condition((RSAPublicKey) rsaKeyPair.getPublic());
  ed25519Condition = new Ed25519Sha256Condition((EdDSAPublicKey) edDsaKeyPair.getPublic());
  prefixSha256Condition
      = new PrefixSha256Condition(prefix, 1000, ed25519Condition);
  thresholdCondition = new ThresholdSha256Condition(
      2,
      Lists.newArrayList(preimageCondition, rsaCondition, prefixSha256Condition)
  );

  byte[] rsaSignature = rsaSigner.sign();
  byte[] edDsaSignature = edDsaSigner.sign();
  preimageFulfillment = new PreimageSha256Fulfillment(preimage);
  rsaFulfillment = new RsaSha256Fulfillment((RSAPublicKey) rsaKeyPair.getPublic(), rsaSignature);
  ed25519Fulfillment =
      new Ed25519Sha256Fulfillment((EdDSAPublicKey) edDsaKeyPair.getPublic(), edDsaSignature);
  prefixSha256Fulfillment =
      new PrefixSha256Fulfillment(prefix, 1000, ed25519Fulfillment);
  thresholdFulfillment =
      new ThresholdSha256Fulfillment(
          Lists.newArrayList(rsaCondition),
          Lists.newArrayList(preimageFulfillment, prefixSha256Fulfillment)
      );
}
 
开发者ID:hyperledger,项目名称:quilt,代码行数:57,代码来源:CryptoConditionReaderWriterTest.java


注:本文中的java.security.spec.RSAKeyGenParameterSpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。