Package java.security.spec

Examples of java.security.spec.InvalidKeySpecException


            throw new SshException("Expected curve " + expectedCurveName + " but was " + curveName);
        }

        ECPoint group = ECCurves.decodeECPoint(groupBytes, spec.getCurve());
        if (group == null) {
            throw new InvalidKeySpecException("Couldn't decode EC group");
        }

        KeyFactory keyFactory = SecurityUtils.getKeyFactory("EC");
        PublicKey pubKey = keyFactory.generatePublic(new ECPublicKeySpec(group, spec));
        PrivateKey privKey = keyFactory.generatePrivate(new ECPrivateKeySpec(exponent, spec));
View Full Code Here


        } catch (InvalidKeyException e) {
            throw new InvalidKeyException("InvalidKeyException due to invalid passPhrase: " + Arrays.toString(passPhrase));
        } catch (NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException("NoSuchAlgorithmException while using algorithm: " + algorithm);
        } catch (InvalidKeySpecException e) {
            throw new InvalidKeySpecException("Invalid Key generated while using passPhrase: " + Arrays.toString(passPhrase));
        }
        return secretKey;
    }
View Full Code Here

            {
                pki = SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey));
            }
            catch (IOException e)
            {
                throw new InvalidKeySpecException(e.toString());
            }


            try
            {
                // --- Build and return the actual key.
                ASN1Primitive innerType = pki.parsePublicKey();
                ASN1Sequence publicKey = (ASN1Sequence)innerType;

                // decode oidString (but we don't need it right now)
                String oidString = ((ASN1ObjectIdentifier)publicKey.getObjectAt(0))
                    .toString();

                // decode <n>
                BigInteger bigN = ((ASN1Integer)publicKey.getObjectAt(1)).getValue();
                int n = bigN.intValue();

                // decode <t>
                BigInteger bigT = ((ASN1Integer)publicKey.getObjectAt(2)).getValue();
                int t = bigT.intValue();

                // decode <matrixG>
                byte[] matrixG = ((ASN1OctetString)publicKey.getObjectAt(3)).getOctets();

                return new BCMcElieceCCA2PublicKey(new McElieceCCA2PublicKeySpec(
                    OID, n, t, matrixG));
            }
            catch (IOException cce)
            {
                throw new InvalidKeySpecException(
                    "Unable to decode X509EncodedKeySpec: "
                        + cce.getMessage());
            }
        }

        throw new InvalidKeySpecException("Unsupported key specification: "
            + keySpec.getClass() + ".");
    }
View Full Code Here

            {
                pki = PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey));
            }
            catch (IOException e)
            {
                throw new InvalidKeySpecException("Unable to decode PKCS8EncodedKeySpec: " + e);
            }

            try
            {
                // get the inner type inside the BIT STRING
                ASN1Primitive innerType = pki.parsePrivateKey().toASN1Primitive();

                // build and return the actual key
                ASN1Sequence privKey = (ASN1Sequence)innerType;

                // decode oidString (but we don't need it right now)
                String oidString = ((ASN1ObjectIdentifier)privKey.getObjectAt(0))
                    .toString();

                // decode <n>
                BigInteger bigN = ((ASN1Integer)privKey.getObjectAt(1)).getValue();
                int n = bigN.intValue();

                // decode <k>
                BigInteger bigK = ((ASN1Integer)privKey.getObjectAt(2)).getValue();
                int k = bigK.intValue();


                // decode <fieldPoly>
                byte[] encFieldPoly = ((ASN1OctetString)privKey.getObjectAt(3))
                    .getOctets();
                // decode <goppaPoly>
                byte[] encGoppaPoly = ((ASN1OctetString)privKey.getObjectAt(4))
                    .getOctets();
                // decode <p>
                byte[] encP = ((ASN1OctetString)privKey.getObjectAt(5)).getOctets();
                // decode <h>
                byte[] encH = ((ASN1OctetString)privKey.getObjectAt(6)).getOctets();
                // decode <qInv>
                ASN1Sequence qSeq = (ASN1Sequence)privKey.getObjectAt(7);
                byte[][] encQInv = new byte[qSeq.size()][];
                for (int i = 0; i < qSeq.size(); i++)
                {
                    encQInv[i] = ((ASN1OctetString)qSeq.getObjectAt(i)).getOctets();
                }

                return new BCMcElieceCCA2PrivateKey(
                    new McElieceCCA2PrivateKeySpec(OID, n, k, encFieldPoly,
                        encGoppaPoly, encP, encH, encQInv));

            }
            catch (IOException cce)
            {
                throw new InvalidKeySpecException(
                    "Unable to decode PKCS8EncodedKeySpec.");
            }
        }

        throw new InvalidKeySpecException("Unsupported key specification: "
            + keySpec.getClass() + ".");
    }
View Full Code Here

                    .getT(), pubKey.getG());
            }
        }
        else
        {
            throw new InvalidKeySpecException("Unsupported key type: "
                + key.getClass() + ".");
        }

        throw new InvalidKeySpecException("Unknown key specification: "
            + keySpec + ".");
    }
View Full Code Here

            McElieceCCA2PublicKey key = McElieceCCA2PublicKey.getInstance((ASN1Sequence)innerType);
            return new BCMcElieceCCA2PublicKey(key.getOID().getId(), key.getN(), key.getT(), key.getG());
        }
        catch (IOException cce)
        {
            throw new InvalidKeySpecException("Unable to decode X509EncodedKeySpec");
        }
    }
View Full Code Here

            McElieceCCA2PrivateKey key = McElieceCCA2PrivateKey.getInstance(innerType);
            return new BCMcElieceCCA2PrivateKey(key.getOID().getId(), key.getN(), key.getK(), key.getField(), key.getGoppaPoly(), key.getP(), key.getH(), key.getQInv());
        }
        catch (IOException cce)
        {
            throw new InvalidKeySpecException("Unable to decode PKCS8EncodedKeySpec");
        }
    }
View Full Code Here

            {
                pki = SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey));
            }
            catch (IOException e)
            {
                throw new InvalidKeySpecException(e.toString());
            }

            try
            {
                // --- Build and return the actual key.
                ASN1Primitive innerType = pki.parsePublicKey();
                ASN1Sequence publicKey = (ASN1Sequence)innerType;

                // decode oidString (but we don't need it right now)
                String oidString = ((ASN1ObjectIdentifier)publicKey.getObjectAt(0))
                    .toString();

                // decode <n>
                BigInteger bigN = ((ASN1Integer)publicKey.getObjectAt(1)).getValue();
                int n = bigN.intValue();

                // decode <t>
                BigInteger bigT = ((ASN1Integer)publicKey.getObjectAt(2)).getValue();
                int t = bigT.intValue();

                // decode <matrixG>
                byte[] matrixG = ((ASN1OctetString)publicKey.getObjectAt(3)).getOctets();


                return new BCMcEliecePublicKey(new McEliecePublicKeySpec(OID, t, n,
                    matrixG));
            }
            catch (IOException cce)
            {
                throw new InvalidKeySpecException(
                    "Unable to decode X509EncodedKeySpec: "
                        + cce.getMessage());
            }
        }

        throw new InvalidKeySpecException("Unsupported key specification: "
            + keySpec.getClass() + ".");
    }
View Full Code Here

            {
                pki = PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey));
            }
            catch (IOException e)
            {
                throw new InvalidKeySpecException("Unable to decode PKCS8EncodedKeySpec: " + e);
            }

            try
            {
                ASN1Primitive innerType = pki.parsePrivateKey().toASN1Primitive();

                // build and return the actual key
                ASN1Sequence privKey = (ASN1Sequence)innerType;

                // decode oidString (but we don't need it right now)
                String oidString = ((ASN1ObjectIdentifier)privKey.getObjectAt(0))
                    .toString();

                // decode <n>
                BigInteger bigN = ((ASN1Integer)privKey.getObjectAt(1)).getValue();
                int n = bigN.intValue();

                // decode <k>
                BigInteger bigK = ((ASN1Integer)privKey.getObjectAt(2)).getValue();
                int k = bigK.intValue();

                // decode <fieldPoly>
                byte[] encFieldPoly = ((ASN1OctetString)privKey.getObjectAt(3))
                    .getOctets();
                // decode <goppaPoly>
                byte[] encGoppaPoly = ((ASN1OctetString)privKey.getObjectAt(4))
                    .getOctets();

                // decode <sInv>
                byte[] encSInv = ((ASN1OctetString)privKey.getObjectAt(5)).getOctets();
                // decode <p1>
                byte[] encP1 = ((ASN1OctetString)privKey.getObjectAt(6)).getOctets();
                // decode <p2>
                byte[] encP2 = ((ASN1OctetString)privKey.getObjectAt(7)).getOctets();

                //decode <h>
                byte[] encH = ((ASN1OctetString)privKey.getObjectAt(8)).getOctets();

                // decode <qInv>
                ASN1Sequence qSeq = (ASN1Sequence)privKey.getObjectAt(9);
                byte[][] encQInv = new byte[qSeq.size()][];
                for (int i = 0; i < qSeq.size(); i++)
                {
                    encQInv[i] = ((ASN1OctetString)qSeq.getObjectAt(i)).getOctets();
                }

                return new BCMcEliecePrivateKey(new McEliecePrivateKeySpec(OID, n, k,
                    encFieldPoly, encGoppaPoly, encSInv, encP1, encP2,
                    encH, encQInv));

            }
            catch (IOException cce)
            {
                throw new InvalidKeySpecException(
                    "Unable to decode PKCS8EncodedKeySpec.");
            }
        }

        throw new InvalidKeySpecException("Unsupported key specification: "
            + keySpec.getClass() + ".");
    }
View Full Code Here

                    pubKey.getG());
            }
        }
        else
        {
            throw new InvalidKeySpecException("Unsupported key type: "
                + key.getClass() + ".");
        }

        throw new InvalidKeySpecException("Unknown key specification: "
            + keySpec + ".");
    }
View Full Code Here

TOP

Related Classes of java.security.spec.InvalidKeySpecException

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.