Package java.security.interfaces

Examples of java.security.interfaces.RSAPublicKey


      p = new DOMCryptoBinary(params.getP());
      q = new DOMCryptoBinary(params.getQ());
      g = new DOMCryptoBinary(params.getG());
      y = new DOMCryptoBinary(dkey.getY());
  } else if (key instanceof RSAPublicKey) {
      RSAPublicKey rkey = (RSAPublicKey) key;
      exponent = new DOMCryptoBinary(rkey.getPublicExponent());
      modulus = new DOMCryptoBinary(rkey.getModulus());
  } else {
      throw new KeyException("unsupported key algorithm: " +
    key.getAlgorithm());
  }
    }
View Full Code Here


    assertEquals(certId, myid);
  }

  public void test02getSigningAlgFromAlgSelection() throws Exception {
   
    RSAPublicKey rsa = new MockRSAPublicKey();
    assertEquals("SHA1WithRSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithRSA;SHA1WithECDSA", rsa));
    assertEquals("SHA1WithRSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA256WithECDSA;SHA1WithECDSA;SHA1WithRSA", rsa));
    assertEquals("SHA1WithRSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithRSA", rsa));
    assertEquals("SHA1WithRSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithECDSA;SHA1WithRSA", rsa));
View Full Code Here

       
        // Transform the PublicKey to be sure we have it in a format that the X509 certificate generator handles, it might be
        // a CVC public key that is passed as parameter
        PublicKey publicKey = null;
        if (pubKey instanceof RSAPublicKey) {
          RSAPublicKey rsapk = (RSAPublicKey)pubKey;
        RSAPublicKeySpec rSAPublicKeySpec = new RSAPublicKeySpec(rsapk.getModulus(), rsapk.getPublicExponent());       
        try {
        publicKey = KeyFactory.getInstance("RSA").generatePublic(rSAPublicKeySpec);
      } catch (InvalidKeySpecException e) {
        log.error("Error creating RSAPublicKey from spec: ", e);
        publicKey = pubKey;
View Full Code Here

     * Generate the key.
     * @return the key
     */
    private KeyPair generateKeyPair() {

        final RSAPublicKey oldPublicKey; {
            final PublicKey tmpPublicKey = this.privateKeyContainerKeyStore.certificate.getPublicKey();
            if ( !(tmpPublicKey instanceof RSAPublicKey) ) {
                m_log.error("Only RSA keys could be renewed.");
                return null;
            }
            oldPublicKey = (RSAPublicKey)tmpPublicKey;
        }
        final KeyPairGenerator kpg;
        try {
            kpg = KeyPairGenerator.getInstance("RSA", this.privateKeyContainerKeyStore.providerName);
            kpg.initialize(oldPublicKey.getModulus().bitLength());
            return kpg.generateKeyPair();
        } catch (Throwable e) {
            m_log.error("Key generation problem.", e);
            return null;
        }
View Full Code Here

     * for example if the key is an EC key and the "implicitlyCA" encoding is used.
     */
  public static int getKeyLength(final PublicKey pk) {
    int len = -1;
    if (pk instanceof RSAPublicKey) {
      final RSAPublicKey rsapub = (RSAPublicKey) pk;
      len = rsapub.getModulus().bitLength();
    } else if (pk instanceof JCEECPublicKey) {
      final JCEECPublicKey ecpriv = (JCEECPublicKey) pk;
      final org.bouncycastle.jce.spec.ECParameterSpec spec = ecpriv.getParameters();
      if (spec != null) {
        len = spec.getN().bitLength();       
View Full Code Here

      return null;
    }
    AlgorithmParameterSpec ret = null;
    if (pk instanceof RSAPublicKey) {
      log.debug("getKeyGenSpec: RSA");
      final RSAPublicKey rpk = (RSAPublicKey)pk;
      ret = new RSAKeyGenParameterSpec(getKeyLength(pk), rpk.getPublicExponent());
    } else if (pk instanceof DSAPublicKey) {
      log.debug("getKeyGenSpec: DSA");
      final DSAPublicKey dpk = (DSAPublicKey)pk;
      final DSAParams params = dpk.getParams();
      ret = new DSAParameterSpec(params.getP(), params.getQ(), params.getG());
View Full Code Here

     * @param ps stream to print to.
     */
    public static void printPublicKeyInfo(final PublicKey publK, final PrintStream ps) {
        if ( publK instanceof RSAPublicKey ) {
            ps.println("RSA key:");
            final RSAPublicKey rsa = (RSAPublicKey)publK;
            ps.println("  modulus: "+rsa.getModulus().toString(16));
            ps.println("  public exponent: "+rsa.getPublicExponent().toString(16));
            return;
        }
        if ( publK instanceof ECPublicKey ) {
            ps.println("Elliptic curve key:");
            final ECPublicKey ec = (ECPublicKey)publK;
View Full Code Here

       keyInfoType.getContent().add(sigFactory.createKeyName(keyName));                         
     }

     if(req.getRespondWith().contains(XKMSConstants.RESPONDWITH_KEYVALUE)){
       if(cert.getPublicKey() instanceof RSAPublicKey){ 
         RSAPublicKey pubKey = (RSAPublicKey) cert.getPublicKey();       
         RSAKeyValueType rSAKeyValueType = sigFactory.createRSAKeyValueType();
         rSAKeyValueType.setModulus(pubKey.getModulus().toByteArray());
         rSAKeyValueType.setExponent(pubKey.getPublicExponent().toByteArray());
         KeyValueType keyValue = sigFactory.createKeyValueType();
         keyValue.getContent().add(sigFactory.createRSAKeyValue(rSAKeyValueType));
         keyInfoType.getContent().add(sigFactory.createKeyValue(keyValue));                         
       }else{
         log.error(intres.getLocalizedMessage("xkms.onlyrsakeysupported"));        
View Full Code Here

        JAXBElement<RegisterRequestType> registerRequest2 = (JAXBElement<RegisterRequestType>) unmarshaller.unmarshal(bais);
        registerRequestType = registerRequest2.getValue();
       
        RSAKeyValueType rSAKeyValueType  = (RSAKeyValueType) ((JAXBElement) registerRequestType.getPrototypeKeyBinding().getKeyInfo().getContent().get(0)).getValue();       
        RSAPublicKeySpec rSAPublicKeySpec = new RSAPublicKeySpec(new BigInteger(rSAKeyValueType.getModulus()), new BigInteger(rSAKeyValueType.getExponent()));       
        RSAPublicKey rSAPublicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(rSAPublicKeySpec);
       
        X509Certificate cert = CertTools.genSelfCert("CN=test", 10, null,keys.getPrivate(), rSAPublicKey, "SHA1WithRSA", true);
       
        cert.verify(rSAPublicKey)
  }
View Full Code Here

        store.load(is, "foo123".toCharArray());
        assertTrue(store.containsAlias("ReqTest"));
        X509Certificate cert = (X509Certificate) store.getCertificate("ReqTest");
        PublicKey pk = cert.getPublicKey();
        if (pk instanceof RSAPublicKey) {
            RSAPublicKey rsapk = (RSAPublicKey) pk;
            assertEquals(rsapk.getAlgorithm(), "RSA");
            assertEquals(2048, rsapk.getModulus().bitLength());
        } else {
            assertTrue("Public key is not RSA", false);
        }

        log.trace("<test01RequestPKCS12()");
View Full Code Here

TOP

Related Classes of java.security.interfaces.RSAPublicKey

Copyright © 2018 www.massapicom. 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.