Examples of RSAPrivateCrtKey


Examples of java.security.interfaces.RSAPrivateCrtKey

        if ( o == this )
        {
            return true;
        }

        RSAPrivateCrtKey key = (RSAPrivateCrtKey)o;

        return this.getModulus().equals(key.getModulus())
         && this.getPublicExponent().equals(key.getPublicExponent())
         && this.getPrivateExponent().equals(key.getPrivateExponent())
         && this.getPrimeP().equals(key.getPrimeP())
         && this.getPrimeQ().equals(key.getPrimeQ())
         && this.getPrimeExponentP().equals(key.getPrimeExponentP())
         && this.getPrimeExponentQ().equals(key.getPrimeExponentQ())
         && this.getCrtCoefficient().equals(key.getCrtCoefficient());
    }
View Full Code Here

Examples of java.security.interfaces.RSAPrivateCrtKey

            store = KeyStore.getInstance("jks");
            store.load(resource.getInputStream(), this.password);
          }
        }
      }
      RSAPrivateCrtKey key = (RSAPrivateCrtKey) store.getKey(alias, password);
      RSAPublicKeySpec spec = new RSAPublicKeySpec(key.getModulus(), key.getPublicExponent());
      PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(spec);
      return new KeyPair(publicKey, key);
    }
    catch (Exception e) {
      throw new IllegalStateException("Cannot load keys from store: " + resource, e);
View Full Code Here

Examples of java.security.interfaces.RSAPrivateCrtKey

        switch (pub.getAlgorithm())
        {
        case PGPPublicKey.RSA_ENCRYPT:
        case PGPPublicKey.RSA_SIGN:
        case PGPPublicKey.RSA_GENERAL:
            RSAPrivateCrtKey rsK = (RSAPrivateCrtKey)privKey;

            privPk = new RSASecretBCPGKey(rsK.getPrivateExponent(), rsK.getPrimeP(), rsK.getPrimeQ());
            break;
        case PGPPublicKey.DSA:
            DSAPrivateKey dsK = (DSAPrivateKey)privKey;

            privPk = new DSASecretBCPGKey(dsK.getX());
View Full Code Here

Examples of java.security.interfaces.RSAPrivateCrtKey

        this.privateKey = privateKey;
        this.keyID = keyID;

        if (privateKey instanceof  RSAPrivateCrtKey)
        {
            RSAPrivateCrtKey rsK = (RSAPrivateCrtKey)privateKey;

            privateKeyDataPacket = new RSASecretBCPGKey(rsK.getPrivateExponent(), rsK.getPrimeP(), rsK.getPrimeQ());
        }
        else if (privateKey instanceof DSAPrivateKey)
        {
            DSAPrivateKey dsK = (DSAPrivateKey)privateKey;
View Full Code Here

Examples of java.security.interfaces.RSAPrivateCrtKey

                                     new BigInteger(1, expoQ),
                                     new BigInteger(1, coeff));

        // Create an RSA private key from the CRT specification
        KeyFactory kf = KeyFactory.getInstance("RSA", "SunRsaSign");
        RSAPrivateCrtKey rsaPriKey =
            (RSAPrivateCrtKey) kf.generatePrivate(rsaCrtSpec);

        // test resulting key against original specification
        if (!rsaPriKey.getCrtCoefficient().equals(rsaCrtSpec.getCrtCoefficient()))
            throw new Exception("coefficients not equal");
        if (!rsaPriKey.getPrimeExponentP().equals(rsaCrtSpec.getPrimeExponentP()))
            throw new Exception("primeExponentPs not equal");
        if (!rsaPriKey.getPrimeExponentQ().equals(rsaCrtSpec.getPrimeExponentQ()))
            throw new Exception("primeExponentQs not equal");
        if (!rsaPriKey.getPrimeP().equals(rsaCrtSpec.getPrimeP()))
            throw new Exception("primePs not equal");
        if (!rsaPriKey.getPrimeQ().equals(rsaCrtSpec.getPrimeQ()))
            throw new Exception("primeQs not equal");
        if (!rsaPriKey.getPublicExponent().equals(rsaCrtSpec.getPublicExponent()))
            throw new Exception("public exponents not equal");
        if (!rsaPriKey.getPrivateExponent().equals(rsaCrtSpec.getPrivateExponent()))
            throw new Exception("private exponents not equal");
        if (!rsaPriKey.getModulus().equals(rsaCrtSpec.getModulus()))
            throw new Exception("modulus not equal");
        if (!rsaPriKey.getFormat().equals("PKCS#8") &&
            !rsaPriKey.getFormat().equals("PKCS8"))
            throw new Exception("format not PKCS#8");
        if (!rsaPriKey.getAlgorithm().equals("RSA"))
            throw new Exception("algorithm not RSA");
        if (rsaPriKey.getEncoded() == null)
            throw new Exception("encoded key is null");

        PKCS8EncodedKeySpec pkcs8Key =
            new PKCS8EncodedKeySpec(rsaPriKey.getEncoded());

        RSAPrivateCrtKey rsaPriKey2
            = (RSAPrivateCrtKey) kf.generatePrivate(pkcs8Key);
        if (!Arrays.equals(rsaPriKey.getEncoded(), rsaPriKey2.getEncoded()))
            throw new Exception("encoded keys not equal");
    }
View Full Code Here

Examples of java.security.interfaces.RSAPrivateCrtKey

      Pems.x509Certificate(Payloads.newStringPayload(CERTIFICATE), CertificateFactory.getInstance("X.509"));
   }

   @Test
   public void testPrivateKeySpecPem() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException {
      RSAPrivateCrtKey key = (RSAPrivateCrtKey) KeyFactory.getInstance("RSA").generatePrivate(
            Pems.privateKeySpec(Payloads.newStringPayload(PRIVATE_KEY)));
      String encoded = Pems.pem(key);
      assertEquals(encoded, PRIVATE_KEY.replaceAll("\n", ls));
   }
View Full Code Here

Examples of java.security.interfaces.RSAPrivateCrtKey

        }



        //Get PrivateKey
        RSAPrivateCrtKey jksPrivateCrtKey = null;
        try {
            jksPrivateCrtKey =
                    (RSAPrivateCrtKey) jksKeyStore.getKey(jksAlias, jksPassword);
            System.out.println("Get PKCS#12 RSAPrivateCrtKey(" + jksPrivateCrtKey +
                    "): [Bit-Length: " + jksPrivateCrtKey.getModulus().bitLength() +
                    ", Modulus: " + jksPrivateCrtKey.getModulus() +
                    ", PublicExponent: " + jksPrivateCrtKey.getPublicExponent() +
                    ", PrivateExponent: " + jksPrivateCrtKey.getPrivateExponent() +
                    ", Prime-P: " + jksPrivateCrtKey.getPrimeP() +
                    ", Prime-Q: " + jksPrivateCrtKey.getPrimeQ() +
                    ", Prime-Exponent-P: " + jksPrivateCrtKey.getPrimeExponentP() +
                    ", Prime-Exponent-Q: " + jksPrivateCrtKey.getPrimeExponentQ() +
                    ", CRT-Coefficient: " + jksPrivateCrtKey.getCrtCoefficient()
            );
        } catch (KeyStoreException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (UnrecoverableKeyException e) {
            e.printStackTrace();
            System.exit(1);
        }

        //Get Certificate
        Certificate jksCert = null;
        try {
            jksCert = jksKeyStore.getCertificate(jksAlias);
            System.out.println("Get Certificate from PKCS#12: " + jksCert);
        } catch (KeyStoreException e) {
            e.printStackTrace();
            System.exit(1);
        }

        //Get Certificate Chain
        Certificate[] jksCerts = null;
        try {
            jksCerts = jksKeyStore.getCertificateChain(jksAlias);
            System.out.println("Get Certificate Chain from JKS, with " +
                    jksCerts.length + " certs.");
            for (int i = 0; i < jksCerts.length; i++) {
                System.out.println("Certificate " + (i + 1) +
                        " from JKS in the chain: " + jksCerts[i]);
            }
        } catch (KeyStoreException e) {
            e.printStackTrace();
            System.exit(1);
        }

        //=====================================
        // PKCS#12 stuff
        //=====================================

        KeyStore pkcs12KeyStore = null;
        try {
            pkcs12KeyStore = KeyStore.getInstance("PKCS12", "BC");
            System.out.println("Create PKCS#12 KeyStore Object.");
        } catch (KeyStoreException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (NoSuchProviderException e) {
            e.printStackTrace();
            System.exit(1);
        }
        try {
            pkcs12KeyStore.load(null, pkcs12Password);
            System.out.println(
                    "Load a new fresh PKCS#12 KeyStore from scratch.");
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (CertificateException e) {
            e.printStackTrace();
            System.exit(1);
        }
        try {
            pkcs12KeyStore.setKeyEntry(pkcs12Alias, jksPrivateCrtKey,
                    pkcs12Password, jksCerts);
            System.out.println("Add the RSA Private Crt Key and the " +
                    "Certificate Chain to the PKCS#12 KeyStore.");
        } catch (KeyStoreException e) {
            e.printStackTrace();
            System.exit(1);
        }
        OutputStream pkcs12OutputStream = null;
        try {
            pkcs12OutputStream = new FileOutputStream(pkcs12FileName);
            System.out.println(
                    "Establish PKCS#12 OutputStream to " + pkcs12FileName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        }
        try {
            pkcs12KeyStore.store(pkcs12OutputStream, pkcs12Password);
            pkcs12OutputStream.close();
            System.out.println("Store PKCS#12 KeyStore: " + pkcs12FileName);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (KeyStoreException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (CertificateException e) {
            e.printStackTrace();
            System.exit(1);
        }

        //=====================================
        // Reread the pkcs12KeyStore
        //=====================================

        InputStream pkcs12InputStream = null;
        try {
            pkcs12InputStream = new FileInputStream(pkcs12FileName);
            System.out.println(
                    "Establish PKCS#12 InputStream to " + pkcs12FileName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        }
        try {
            pkcs12KeyStore.load(pkcs12InputStream, pkcs12Password);
            System.out.println("Re-read the PKCS#12 KeyStore.");
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (CertificateException e) {
            e.printStackTrace();
            System.exit(1);
        }

        //Get PrivateKey
        RSAPrivateCrtKey pkcs12PrivateCrtKey = null;
        try {
            pkcs12PrivateCrtKey =
                    (RSAPrivateCrtKey) pkcs12KeyStore.getKey(pkcs12Alias, pkcs12Password);
            System.out.println(
                    "Get PKCS#12 RSAPrivateCrtKey(" + pkcs12PrivateCrtKey +
                    "): [Bit-Length: " + pkcs12PrivateCrtKey.getModulus().bitLength() +
                    ", Modulus: " + pkcs12PrivateCrtKey.getModulus() +
                    ", PublicExponent: " + pkcs12PrivateCrtKey.getPublicExponent() +
                    ", PrivateExponent: " + pkcs12PrivateCrtKey.getPrivateExponent() +
                    ", Prime-P: " + pkcs12PrivateCrtKey.getPrimeP() +
                    ", Prime-Q: " + pkcs12PrivateCrtKey.getPrimeQ() +
                    ", Prime-Exponent-P: " + pkcs12PrivateCrtKey.getPrimeExponentP() +
                    ", Prime-Exponent-Q: " + pkcs12PrivateCrtKey.getPrimeExponentQ() +
                    ", CRT-Coefficient: " + pkcs12PrivateCrtKey.getCrtCoefficient()
            );
        } catch (KeyStoreException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (NoSuchAlgorithmException e) {
View Full Code Here

Examples of java.security.interfaces.RSAPrivateCrtKey

                this.Aq=trimba(privkey.getAq().toByteArray());
            } else {
                // key wurde mit Java erzeugt, es m�ssen noch ein paar Parameter,
                // die f�rs SIZ-file ben�tigt werden, errechnet werden
               
                RSAPrivateCrtKey privkey=(RSAPrivateCrtKey)key;
                this.p=trimba(privkey.getPrimeP().toByteArray());
                this.q=trimba(privkey.getPrimeQ().toByteArray());
                this.dP=trimba(privkey.getPrimeExponentP().toByteArray());
                this.dQ=trimba(privkey.getPrimeExponentQ().toByteArray());
               
                BigInteger one=new BigInteger("1");
                BigInteger modulus=new BigInteger(+1,this.p).multiply(new BigInteger(+1,this.q));
               
                this.Ap=trimba(new BigInteger(+1,this.q).modPow(new BigInteger(+1,this.p).subtract(one),modulus).toByteArray());
View Full Code Here

Examples of java.security.interfaces.RSAPrivateCrtKey

        {
            putBigIntAsBase64UrlEncodedParam(params, PRIVATE_EXPONENT_MEMBER_NAME, rsaPrivateKey.getPrivateExponent());

          if (rsaPrivateKey instanceof RSAPrivateCrtKey)
          {
              RSAPrivateCrtKey crt = (RSAPrivateCrtKey) rsaPrivateKey;
              putBigIntAsBase64UrlEncodedParam(params, FIRST_PRIME_FACTOR_MEMBER_NAME, crt.getPrimeP());
              putBigIntAsBase64UrlEncodedParam(params, SECOND_PRIME_FACTOR_MEMBER_NAME, crt.getPrimeQ());
              putBigIntAsBase64UrlEncodedParam(params, FIRST_FACTOR_CRT_EXPONENT_MEMBER_NAME, crt.getPrimeExponentP());
              putBigIntAsBase64UrlEncodedParam(params, SECOND_FACTOR_CRT_EXPONENT_MEMBER_NAME, crt.getPrimeExponentQ());
              putBigIntAsBase64UrlEncodedParam(params, FIRST_CRT_COEFFICIENT_MEMBER_NAME, crt.getCrtCoefficient());
          }
        }
    }
View Full Code Here

Examples of java.security.interfaces.RSAPrivateCrtKey

        if (obj instanceof RSAPrivateCrtKey)
        {
            type = "RSA PRIVATE KEY";

            RSAPrivateCrtKey k = (RSAPrivateCrtKey)obj;

            RSAPrivateKeyStructure keyStruct = new RSAPrivateKeyStructure(
                k.getModulus(),
                k.getPublicExponent(),
                k.getPrivateExponent(),
                k.getPrimeP(),
                k.getPrimeQ(),
                k.getPrimeExponentP(),
                k.getPrimeExponentQ(),
                k.getCrtCoefficient());

            // convert to bytearray
            keyData = keyStruct.getEncoded();
        }
        else if (obj instanceof DSAPrivateKey)
        {
            type = "DSA PRIVATE KEY";

            DSAPrivateKey       k = (DSAPrivateKey)obj;
            DSAParams           p = k.getParams();
            ASN1EncodableVector v = new ASN1EncodableVector();

            v.add(new DERInteger(0));
            v.add(new DERInteger(p.getP()));
            v.add(new DERInteger(p.getQ()));
            v.add(new DERInteger(p.getG()));

            BigInteger x = k.getX();
            BigInteger y = p.getG().modPow(x, p.getP());

            v.add(new DERInteger(y));
            v.add(new DERInteger(x));
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.