Java 8 KeyPairGenerator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 KeyPairGenerator class.

This code example shows how to use the following methods:genKeyPair, initialize
This code example shows how to use the following methods:initialize
 
    serializedStore = new File(root, "cybervillainsCA.jks");
 
    try { 
      pairGenerator = KeyPairGenerator.getInstance("RSA");
      pairGenerator.initialize(1024);
 
      caCert = readRootSigningCert();
    } catch (NoSuchAlgorithmException e) {
      throw Throwables.propagate(e);
    } 
  } 
 
  public KeyAndCert generateCertificate(String hostname, String certificateRevocationList) {
    X500Principal x500issuer = caCert.getCertificate().getIssuerX500Principal();
    String subject = String.format(
        "CN=%s, OU=Test, O=CyberVillainsCA, L=Seattle, S=Washington, C=US", hostname);
    X500Principal x500subject = new X500Principal(subject);
 
    Date begin = new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1));
6
CodeRank
This code example shows how to use the following methods:genKeyPair, initialize
    *           for initializing {@code generator} 
    * @return new 2048 bit keyPair 
    * @see Crypto#rsaKeyPairGenerator() 
    */ 
   public static KeyPair generateRsaKeyPair(KeyPairGenerator generator, SecureRandom rand) {
      generator.initialize(2048, rand);
      return generator.genKeyPair();
   } 
 
   /** 
    * return a "public" -> rsa public key, "private" -> its corresponding private key 
    */ 
   public static Map<String, String> generate() {
      try { 
         return generate(KeyPairGenerator.getInstance("RSA"), new SecureRandom());
      } catch (NoSuchAlgorithmException e) {
         throw propagate(e);
      } 
   } 
 
6
CodeRank
This code example shows how to use the following methods:generateKeyPair, initialize
                method="method", 
                args={} 
            ) 
    }) 
    public void testKeyPairGenerator() throws NoSuchAlgorithmException { 
        generator.initialize(1024);
 
        KeyPair keyPair = generator.generateKeyPair();
 
        assertNotNull("no keypair generated", keyPair);
        assertNotNull("no public key generated", keyPair.getPublic());
        assertNotNull("no private key generated", keyPair.getPrivate());
 
        helper.test(keyPair);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:generateKeyPair, initialize
        Security.addProvider(new BouncyCastleProvider());
    } 
 
    public CAFactory() throws Exception {
        this.kpGen = KeyPairGenerator.getInstance("RSA", "BC");
        this.kpGen.initialize(1024, new SecureRandom());
        this.certGen = new X509V3CertificateGenerator();
    } 
 
    public X509Certificate create(String baseName,
                                  int months, 
                                  KeyPair keyPair) throws Exception {
 
        final X509Principal newprincipal =
                new X509Principal("O=Auto,OU=" + baseName + ",CN=CA");
         
        this.certGen.reset();
 
        /* 
          "The entity that created the certificate is responsible for  assigning 

5
CodeRank
This code example shows how to use the following methods:genKeyPair, initialize
This code example shows how to use the following methods:genKeyPair
This code example shows how to use the following methods:generateKeyPair
  /** 
   * Generate an RSA Key Pair 
   */ 
  public KeyPair getRSAKeyPair()
  { 
    KeyPair kp = _rsaKpg.generateKeyPair();
    rememberKeyPair(kp);
    return kp;
 
  } 
 
  private synchronized void persistPublicKeyMap() { 
    try { 
      ObjectOutput out =
          new ObjectOutputStream(new FileOutputStream(new File(root, PUB_KEYMAP_SER_FILE)));
      out.writeObject(_mappedPublicKeys);
      out.flush();
      out.close();
    } catch (FileNotFoundException e) {
      // writing, won't happen 
5
CodeRank
This code example shows how to use the following methods:generateKeyPair, initialize
                method="method", 
                args={} 
            ) 
    }) 
    public void testKeyPairGenerator() { 
        generator.initialize(1024);
 
        KeyPair keyPair = generator.generateKeyPair();
 
        assertNotNull("no keypair generated", keyPair);
        assertNotNull("no public key generated", keyPair.getPublic());
        assertNotNull("no private key generated", keyPair.getPrivate());
 
        helper.test(keyPair);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:generateKeyPair
         
        byte[] message = Hex.decode("0102030405060708090a0b0c0d0e0f10111213141516");
        byte[] out1, out2;
 
        // Generate static key pair 
        KeyPair     KeyPair = g.generateKeyPair();
        ECPublicKey   Pub = (ECPublicKey) KeyPair.getPublic();
        ECPrivateKey  Priv = (ECPrivateKey) KeyPair.getPrivate();
 
        Cipher c1 = Cipher.getInstance(cipher);
        Cipher c2 = Cipher.getInstance(cipher);
 
        // Testing with null parameters and DHAES mode off 
        c1.init(Cipher.ENCRYPT_MODE, Pub, new SecureRandom());
        c2.init(Cipher.DECRYPT_MODE, Priv, new SecureRandom());
        out1 = c1.doFinal(message, 0, message.length);
        out2 = c2.doFinal(out1, 0, out1.length);
        if (!areEqual(out2, message))
            fail(testname + " test failed with null parameters, DHAES mode false.");
     
5
CodeRank

Related Java 8 KeyPairGenerator Questions & Answers:

See Code Examples for Java 8 KeyPairGenerator Methods: