Examples of RSAPublicKey


Examples of java.security.interfaces.RSAPublicKey

    byte[] pk;
    IKeyPairCodec codec = new RSAKeyPairRawCodec();
    kp = kpg.generate();

    RSAPublicKey pubK = (RSAPublicKey) kp.getPublic();
    pk = ((GnuRSAPublicKey) pubK).getEncoded(IKeyPairCodec.RAW_FORMAT);
    PublicKey newPubK = codec.decodePublicKey(pk);
    harness.check(pubK.equals(newPubK),
                  "RSA public key Raw encoder/decoder test");

    RSAPrivateKey secK = (RSAPrivateKey) kp.getPrivate();
    pk = ((GnuRSAPrivateKey) secK).getEncoded(IKeyPairCodec.RAW_FORMAT);
    PrivateKey newSecK = codec.decodePrivateKey(pk);
View Full Code Here

Examples of java.security.interfaces.RSAPublicKey

    kp = kpg.generate();

    byte[] pk;

    RSAPublicKey pubK = (RSAPublicKey) kp.getPublic();
    pk = ((GnuRSAPublicKey) pubK).getEncoded(IKeyPairCodec.X509_FORMAT);
    PublicKey newPubK = new RSAKeyPairX509Codec().decodePublicKey(pk);
    harness.check(pubK.equals(newPubK),
                  "RSA public key ASN.1 encoder/decoder test");

    RSAPrivateKey secK = (RSAPrivateKey) kp.getPrivate();
    pk = ((GnuRSAPrivateKey) secK).getEncoded(IKeyPairCodec.PKCS8_FORMAT);
    PrivateKey newSecK = new RSAKeyPairPKCS8Codec().decodePrivateKey(pk);
View Full Code Here

Examples of java.security.interfaces.RSAPublicKey

    harness.checkPoint("testPublicKeyValueOf");

    byte[] pk;
    kp = kpg.generate();

    RSAPublicKey p1 = (RSAPublicKey) kp.getPublic();

    pk = ((GnuRSAPublicKey) p1).getEncoded(IKeyPairCodec.RAW_FORMAT);
    PublicKey p2 = GnuRSAPublicKey.valueOf(pk);
    harness.check(p1.equals(p2),
                  "RSA public key valueOf(<raw-value>) test");

    pk = ((GnuRSAPublicKey) p1).getEncoded(IKeyPairCodec.X509_FORMAT);
    PublicKey p3 = GnuRSAPublicKey.valueOf(pk);
    harness.check(p1.equals(p3),
                  "RSA public key valueOf(<x509-value>) test");
  }
View Full Code Here

Examples of java.security.interfaces.RSAPublicKey

                } else {
                    return -1;
                }
            } else if (a instanceof RSAPublicKey) {
                if (b instanceof RSAPublicKey) {
                    RSAPublicKey da = (RSAPublicKey) a;
                    RSAPublicKey db = (RSAPublicKey) b;
                    int r = da.getPublicExponent().compareTo(db.getPublicExponent());
                    if (r != 0) {
                        return r;
                    }
                    return da.getModulus().compareTo(db.getModulus());
                } else {
                    return -1;
                }
            } else {
                throw new IllegalArgumentException("Only RSA and DAS keys are supported.");
View Full Code Here

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

Examples of java.security.interfaces.RSAPublicKey

    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

Examples of java.security.interfaces.RSAPublicKey

       
        // 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

Examples of java.security.interfaces.RSAPublicKey

     * 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

Examples of java.security.interfaces.RSAPublicKey

     * 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

Examples of java.security.interfaces.RSAPublicKey

      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
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.