Package io.apigee.trireme.core.internal

Examples of io.apigee.trireme.core.internal.CryptoException


                PEMDecryptorProvider dec =
                    new JcePEMDecryptorProviderBuilder().build(passphrase);
                PEMKeyPair kp = ((PEMEncryptedKeyPair)po).decryptKeyPair(dec);
                return convertKeyPair(kp);
            }
            throw new CryptoException("Input data does not contain a key pair");
        } finally {
            pp.close();
        }
    }
View Full Code Here


            }

            if (po instanceof SubjectPublicKeyInfo) {
                return convertPublicKey((SubjectPublicKeyInfo) po);
            }
            throw new CryptoException("Input data does not contain a public key");
        } finally {
            pp.close();
        }
    }
View Full Code Here

            PrivateKey key = factory.generatePrivate(keySpec);

            return new KeyPair(pub, key);

        } catch (GeneralSecurityException gse) {
            throw new CryptoException(gse);
        }
    }
View Full Code Here

            KeyFactory factory = KeyFactory.getInstance("RSA");
            RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(rsa.getModulus(), rsa.getPublicExponent());
            return  factory.generatePublic(pubSpec);

        } catch (GeneralSecurityException gse) {
            throw new CryptoException(gse);
        }
    }
View Full Code Here

    {
        PemReader reader = new PemReader(rdr);

        PemObject pemObj = reader.readPemObject();
        if (pemObj == null) {
            throw new CryptoException("Not a valid PEM file");
        }

        if (!DSA_TYPE.equals(pemObj.getType())) {
            throw new CryptoException("PEM file does not contain a DSA private key");
        }

        ASN1InputStream asnIn = new ASN1InputStream(pemObj.getContent());
        ASN1Primitive ao = asnIn.readObject();
        if (ao == null) {
            throw new CryptoException("PEM file does not contain an ASN.1 object");
        }
        if (!(ao instanceof ASN1Sequence)) {
            throw new CryptoException("PEM file does not contain a sequence");
        }

        ASN1Sequence seq = (ASN1Sequence)ao;
        if (seq.size() != 6) {
            throw new CryptoException("ASN.1 sequence is the wrong length for a DSA key");
        }

        DERInteger p = (DERInteger)seq.getObjectAt(1);
        DERInteger q = (DERInteger)seq.getObjectAt(2);
        DERInteger g = (DERInteger)seq.getObjectAt(3);
        DERInteger y = (DERInteger)seq.getObjectAt(4);
        DERInteger x = (DERInteger)seq.getObjectAt(5);

        try {
            KeyFactory factory = KeyFactory.getInstance("DSA");

            DSAPublicKeySpec pubSpec = new DSAPublicKeySpec(
                y.getValue(),
                p.getValue(),
                q.getValue(),
                g.getValue());
            PublicKey pub = factory.generatePublic(pubSpec);

            DSAPrivateKeySpec keySpec = new DSAPrivateKeySpec(
                x.getValue(),
                p.getValue(),
                q.getValue(),
                g.getValue());
            PrivateKey key = factory.generatePrivate(keySpec);

            return new KeyPair(pub, key);

        } catch (GeneralSecurityException gse) {
            throw new CryptoException(gse);
        }
    }
View Full Code Here

            if (po instanceof SubjectPublicKeyInfo) {
                SubjectPublicKeyInfo pk = (SubjectPublicKeyInfo)po;

                AlgorithmIdentifier alg = pk.getAlgorithm();
                if (!(alg.getParameters() instanceof ASN1Sequence)) {
                    throw new CryptoException("Invalid DSA public key format: Algorithm ID not a Sequence");
                }

                ASN1Sequence identifiers = (ASN1Sequence)(alg.getParameters());
                if (identifiers.size() != 3) {
                    throw new CryptoException("Invalid DSA public key format: Identifier does not have 3 items");
                }

                DERInteger p = (DERInteger)identifiers.getObjectAt(0);
                DERInteger q = (DERInteger)identifiers.getObjectAt(1);
                DERInteger g = (DERInteger)identifiers.getObjectAt(2);

                ASN1Primitive pkPrim = pk.parsePublicKey();
                if (!(pkPrim instanceof ASN1Integer)) {
                    throw new CryptoException("Invalid DSA public key format: Public key is not an integer");
                }
                DERInteger y = (DERInteger)pkPrim;

                try {
                    KeyFactory factory = KeyFactory.getInstance("DSA");
                    DSAPublicKeySpec pubSpec = new DSAPublicKeySpec(
                        y.getValue(),
                        p.getValue(),
                        q.getValue(),
                        g.getValue());
                    return factory.generatePublic(pubSpec);
                } catch (GeneralSecurityException gse) {
                    throw new CryptoException(gse);
                }
            }
            throw new CryptoException("Input data does not contain a public key");
        } finally {
            pp.close();
        }
    }
View Full Code Here

        for (KeyPairProvider p : algs) {
            if (p.isSupported(algorithm)) {
                return p.readKeyPair(algorithm, rdr, passphrase);
            }
        }
        throw new CryptoException("Unsupported key pair algorithm " + algorithm);
    }
View Full Code Here

        for (KeyPairProvider p : algs) {
            if (p.isSupported(algorithm)) {
                return p.readPublicKey(algorithm, rdr);
            }
        }
        throw new CryptoException("Unsupported key pair algorithm " + algorithm);
    }
View Full Code Here

    {
        try {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            return (X509Certificate)cf.generateCertificate(is);
        } catch (GeneralSecurityException gse) {
            throw new CryptoException(gse);
        }
    }
View Full Code Here

TOP

Related Classes of io.apigee.trireme.core.internal.CryptoException

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.