Examples of RSAPrivateKey


Examples of java.security.interfaces.RSAPrivateKey

            org.bouncycastle.asn1.x509.Certificate certificate =
                    org.bouncycastle.asn1.x509.Certificate.getInstance(ASN1Primitive.fromByteArray(cert[0].getEncoded()));

            AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256WITHRSAENCRYPTION");
            AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
            RSAPrivateKey privateRSAKey = (RSAPrivateKey)privKey;
            RSAKeyParameters keyParams = new RSAKeyParameters(true, privateRSAKey.getModulus(), privateRSAKey.getPrivateExponent());
            ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(keyParams);
            CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
            gen.addSignerInfoGenerator(
                    new SignerInfoGeneratorBuilder(new BcDigestCalculatorProvider())
                        .build(sigGen, new X509CertificateHolder(certificate)));
View Full Code Here

Examples of java.security.interfaces.RSAPrivateKey

    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);
    harness.check(secK.equals(newSecK),
                  "RSA private key Raw encoder/decoder test");
  }
View Full Code Here

Examples of java.security.interfaces.RSAPrivateKey

    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);
    harness.check(secK.equals(newSecK),
                  "RSA private key ASN.1 encoder/decoder test");
  }
View Full Code Here

Examples of java.security.interfaces.RSAPrivateKey

    harness.checkPoint("testPrivateKeyValueOf");

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

    RSAPrivateKey p1 = (RSAPrivateKey) kp.getPrivate();

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

    pk = ((GnuRSAPrivateKey) p1).getEncoded(IKeyPairCodec.PKCS8_FORMAT);
    PrivateKey p3 = GnuRSAPrivateKey.valueOf(pk);
    harness.check(p1.equals(p3),
                  "RSA private key valueOf(<pkcs8-value>) test");
  }
View Full Code Here

Examples of java.security.interfaces.RSAPrivateKey

            CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

           
            AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256WITHRSAENCRYPTION");
            AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
            RSAPrivateKey privateRSAKey = (RSAPrivateKey)privateKey;
            RSAKeyParameters keyParams = new RSAKeyParameters(true, privateRSAKey.getModulus(), privateRSAKey.getPrivateExponent());
            ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(keyParams);

            gen.addSignerInfoGenerator(
                    new SignerInfoGeneratorBuilder(new BcDigestCalculatorProvider())
                        .build(sigGen, new X509CertificateHolder(certificate)));
View Full Code Here

Examples of java.security.interfaces.RSAPrivateKey

     * @param privK key to test.
     * @return true if the key is extractable.
     */
    public static boolean isPrivateKeyExtractable(final PrivateKey privK) {
        if ( privK instanceof RSAPrivateKey ) {
            final RSAPrivateKey rsa = (RSAPrivateKey)privK;
            final BigInteger result = rsa.getPrivateExponent();
            return result!=null && result.bitLength()>0;
        }
        if ( privK instanceof ECPrivateKey ) {
            final ECPrivateKey ec = (ECPrivateKey)privK;
            final BigInteger result = ec.getS();
View Full Code Here

Examples of java.security.interfaces.RSAPrivateKey

        JAXBElement<RegisterResultType> registerResult2 = (JAXBElement<RegisterResultType>) unmarshaller.unmarshal(bais);
        registerResultType = registerResult2.getValue();
       
        PrivateKeyType privateKeyType2 = registerResultType.getPrivateKey();
        RSAPrivateKey privkey2 = XKMSUtil.getPrivateKeyFromEncryptedXML(privateKeyType2, "This is total crap");
        X509Certificate cert = CertTools.genSelfCert("CN=test", 10, null,privkey2, keys.getPublic(), "SHA1WithRSA", true);
        cert.verify(keys.getPublic());   
    }   
View Full Code Here

Examples of java.security.interfaces.RSAPrivateKey

   * @return a java RSAPrivateKey
   * @throws StringprepException if the shared secret doesn't conform with the SASLprep profile as specified in the XKMS specification.
   * @throws XMLEncryptionException if any other exception occurs during the processing.
   */
  public static RSAPrivateKey getPrivateKeyFromEncryptedXML(PrivateKeyType privateKeyType, String sharedSecret) throws StringprepException, XMLEncryptionException{
    RSAPrivateKey privkey2 = null;
    try{
    DocumentBuilder db = dbf.newDocumentBuilder();
        Document privateKeyDoc = db.newDocument();
        marshaller.marshal(privateKeyType, privateKeyDoc);
       
View Full Code Here

Examples of java.security.interfaces.RSAPrivateKey

    boolean optionalV3Check = false;

    /** ** get session id from the request header and *** */
    /** ** get private key from servlet context. *** */
    String id = request.getHeader(SOTSignOnToolConstants.SESSION_ID);
    RSAPrivateKey privateKey = (RSAPrivateKey) getServletConfig()
        .getServletContext().getAttribute(id);

    if (privateKey == null) {
      // Error!!
      response.setStatus(SOTSignOnToolConstants.UNKNOWN);
      return;
    }

    /** ** get X509 certificate from the request. *** */
    X509Certificate[] certs = (X509Certificate[]) request
        .getAttribute("javax.servlet.request.X509Certificate");

    // error!
    if (certs == null || certs.length == 0) {
      response.setStatus(SOTSignOnToolConstants.CERT_NOT_FOUND);
      return;
    }
    X509Certificate cert = certs[0];

    /** ** get proxy certificate data from the request. *** */
    String proxyStr = "";

    try {
      DataInputStream dis = new DataInputStream(request.getInputStream());

      proxyStr = dis.readUTF();
      dis.close();
    } catch (Exception e) {
      log.error(e.toString());
    }

    /** ** check whether proxy cert is malicious or not. *** */

    /** ** this check is optional. *** */
    optionalV3Check = (Boolean.valueOf(rb.getString("OPTIONAL_CERT_CHECK")))
        .booleanValue();
    if (optionalV3Check) {
      SOTV3Verifier verifier = new SOTV3Verifier();

      if (!verifier.verifyProxyCert(proxyStr, cert)) {
        log.error("proxy cert invalid!");
        response.setStatus(SOTSignOnToolConstants.CERT_MALICIOUS);
        return;
      }

    }

    /** ** concatenate x509 and proxy and private key and *** */

    /** ** save to a file. *** */
    byte[] converted;

    try {
      converted = convert8to1(privateKey.getEncoded());
    } catch (Exception e) {
      // should never happen.
      log.error(e.toString());
      response.setStatus(SOTSignOnToolConstants.FAILED_SAVE_PROXY);
      return;
View Full Code Here

Examples of java.security.interfaces.RSAPrivateKey

            return new RSAPublicKeySpec(k.getModulus(), k.getPublicExponent());
       }
       else if (spec.isAssignableFrom(RSAPrivateKeySpec.class) && key instanceof RSAPrivateKey)
       {
            RSAPrivateKey    k = (RSAPrivateKey)key;

            return new RSAPrivateKeySpec(k.getModulus(), k.getPrivateExponent());
       }
       else if (spec.isAssignableFrom(RSAPrivateCrtKeySpec.class) && key instanceof RSAPrivateCrtKey)
       {
            RSAPrivateCrtKey    k = (RSAPrivateCrtKey)key;

            return new RSAPrivateCrtKeySpec(
                            k.getModulus(), k.getPublicExponent(),
                            k.getPrivateExponent(),
                            k.getPrimeP(), k.getPrimeQ(),
                            k.getPrimeExponentP(), k.getPrimeExponentQ(),
                            k.getCrtCoefficient());
       }
       else if (spec.isAssignableFrom(DHPrivateKeySpec.class) && key instanceof DHPrivateKey)
       {
           DHPrivateKey k = (DHPrivateKey)key;
          
           return new DHPrivateKeySpec(k.getX(), k.getParams().getP(), k.getParams().getG());
       }
       else if (spec.isAssignableFrom(DHPublicKeySpec.class) && key instanceof DHPublicKey)
       {
           DHPublicKey k = (DHPublicKey)key;
          
           return new DHPublicKeySpec(k.getY(), k.getParams().getP(), k.getParams().getG());
       }

        throw new RuntimeException("not implemented yet " + key + " " + spec);
    }
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.