Package java.security

Examples of java.security.KeyPairGenerator.genKeyPair()


    Set<KeyOperation> ops = new LinkedHashSet<>(Arrays.asList(KeyOperation.SIGN, KeyOperation.VERIFY));

    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512);
    KeyPair keyPair = keyGen.genKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey)keyPair.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey)keyPair.getPrivate();

    RSAKey key = new RSAKey.Builder(publicKey).
      privateKey(privateKey).
View Full Code Here


  public void testKeyConversionRoundTrip()
    throws Exception {

    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512);
    KeyPair keyPair = keyGen.genKeyPair();
    RSAPublicKey rsaPublicKeyIn = (RSAPublicKey)keyPair.getPublic();
    RSAPrivateKey rsaPrivateKeyIn = (RSAPrivateKey)keyPair.getPrivate();

    RSAKey rsaJWK = new RSAKey.Builder(rsaPublicKeyIn).privateKey(rsaPrivateKeyIn).build();
View Full Code Here

  public void testKeyConversionRoundTripWithCRTParams()
    throws Exception {

    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512);
    KeyPair keyPair = keyGen.genKeyPair();
    RSAPublicKey rsaPublicKeyIn = (RSAPublicKey)keyPair.getPublic();
    RSAPrivateCrtKey rsaPrivateKeyIn = (RSAPrivateCrtKey)keyPair.getPrivate();

    RSAKey rsaJWK = new RSAKey(rsaPublicKeyIn, rsaPrivateKeyIn, null, null, null, null, null, null, null);
View Full Code Here

    throws Exception {

    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(2048);

    KeyPair kp = kpg.genKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey)kp.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey)kp.getPrivate();

    JWTClaimsSet claimsSet = new JWTClaimsSet();
    claimsSet.setSubject("alice");
View Full Code Here

      KeyPairGenerator rsaKeyPairGenerator = createMock(KeyPairGenerator.class);
      final SecureRandom secureRandom = createMock(SecureRandom.class);

      expect(crypto.rsaKeyPairGenerator()).andReturn(rsaKeyPairGenerator);
      rsaKeyPairGenerator.initialize(2048, secureRandom);
      expect(rsaKeyPairGenerator.genKeyPair()).andReturn(keyPair);

      replay(crypto, rsaKeyPairGenerator, secureRandom);

      RsaSshKeyPairGenerator supplier = Guice.createInjector(new AbstractModule(){
         protected void configure() {
View Full Code Here

        envelope.setAttributeNS("http://www.w3.org/2000/xmlns/",
            "xmlns", "http://example.org/envelope");
        doc.appendChild(envelope);

        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
        KeyPair kp = kpg.genKeyPair();

        // the policy only grants this test SocketPermission to accept, resolve
        // and connect to localhost so that it can dereference 2nd reference
        URI policyURI =
            new File(System.getProperty("test.src", "."), "policy").toURI();
View Full Code Here

                    new Date(System.currentTimeMillis()+i*1000));
        }
        X500Name owner = new X500Name("CN=CA");
        X509CRLImpl crl = new X509CRLImpl(owner, new Date(), new Date(), badCerts);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
        crl.sign(kpg.genKeyPair().getPrivate(), "SHA1withRSA");
        byte[] data = crl.getEncodedInternal();

        // Check the encoding
        checkData(crl, data, serials);

View Full Code Here

    * @throws GeneralSecurityException
    */
   public static KeyPair generateKeyPair(String algo) throws GeneralSecurityException 
   {
      KeyPairGenerator kpg = KeyPairGenerator.getInstance(algo);
      return kpg.genKeyPair();
   }
  
   /**
    * Get the Public Key from the keystore
    * @param ks
View Full Code Here

               KeyPairGenerator rsaKeyPairGenerator = createMock(KeyPairGenerator.class);
               final SecureRandom secureRandom = createMock(SecureRandom.class);
               expect(crypto.rsaKeyPairGenerator()).andReturn(rsaKeyPairGenerator).anyTimes();
               rsaKeyPairGenerator.initialize(2048, secureRandom);
               expectLastCall().anyTimes();
               expect(rsaKeyPairGenerator.genKeyPair()).andReturn(keyPair).anyTimes();
               replay(crypto, rsaKeyPairGenerator, secureRandom);
               binder.bind(Crypto.class).toInstance(crypto);
               binder.bind(SecureRandom.class).toInstance(secureRandom);
            } catch (NoSuchAlgorithmException e) {
               propagate(e);
View Full Code Here

            ne.initCause( e );
            throw ne;
        }

        generator.initialize( KEY_SIZE );
        KeyPair keypair = generator.genKeyPair();
        entry.put( KEY_ALGORITHM_AT, ALGORITHM );
       
        // Generate the private key attributes
        PrivateKey privateKey = keypair.getPrivate();
        entry.put( PRIVATE_KEY_AT, privateKey.getEncoded() );
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.