Package java.security.spec

Examples of java.security.spec.X509EncodedKeySpec


     * @param base64EncodedKey base64-encoded RSA public key
     * @return a native Java RSAPublicKey
     * @throws KeyException thrown if there is an error constructing key
     */
    public static RSAPublicKey buildJavaRSAPublicKey(String base64EncodedKey) throws KeyException {
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.decode(base64EncodedKey));
        return (RSAPublicKey) buildKey(keySpec, "RSA");
    }
View Full Code Here


     * @param base64EncodedKey base64-encoded EC public key
     * @return a native Java ECPublicKey
     * @throws KeyException thrown if there is an error constructing key
     */
    public static ECPublicKey buildJavaECPublicKey(String base64EncodedKey) throws KeyException {
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.decode(base64EncodedKey));
        return (ECPublicKey) buildKey(keySpec, "EC");
    }
View Full Code Here

       {
               return new PKCS8EncodedKeySpec(key.getEncoded());
       }
       else if (spec.isAssignableFrom(X509EncodedKeySpec.class) && key.getFormat().equals("X.509"))
       {
               return new X509EncodedKeySpec(key.getEncoded());
       }
       else if (spec.isAssignableFrom(RSAPublicKeySpec.class) && key instanceof RSAPublicKey)
       {
            RSAPublicKey    k = (RSAPublicKey)key;
View Full Code Here

     */
    private PublicKey generatePubKey(byte[] encodedKey) {
        PublicKey pubKey=null;
        try {
            KeyFactory KeyFac=KeyFactory.getInstance(getAlgorithm(asymAlgorithm));
            X509EncodedKeySpec x509KeySpec=new X509EncodedKeySpec(encodedKey);
            pubKey=KeyFac.generatePublic(x509KeySpec);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
View Full Code Here

    {
        PublicKey pubKey = null;
        try
        {
            KeyFactory KeyFac = KeyFactory.getInstance(getAlgorithm(asymAlgorithm));
            X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(encodedKey);
            pubKey = KeyFac.generatePublic(x509KeySpec);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
View Full Code Here

            PrivateKey privKey = keyPair.getPrivate();

            byte[] encPubKey = pubKey.getEncoded();
            byte[] encPrivKey = privKey.getEncoded();

            X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encPubKey);
            PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(
                encPrivKey);

            PublicKey decPubKey = kf.generatePublic(pubKeySpec);
            PrivateKey decPrivKey = kf.generatePrivate(privKeySpec);
View Full Code Here

        }
        else if (key instanceof BCRainbowPublicKey)
        {
            if (X509EncodedKeySpec.class.isAssignableFrom(keySpec))
            {
                return new X509EncodedKeySpec(key.getEncoded());
            }
            else if (RainbowPublicKeySpec.class.isAssignableFrom(keySpec))
            {
                BCRainbowPublicKey pubKey = (BCRainbowPublicKey)key;
                return new RainbowPublicKeySpec(pubKey.getDocLength(), pubKey
View Full Code Here

        String f1 = p1.getFormat();
        harness.check("X.509".equalsIgnoreCase(f1),
                      "DSS public key format MUST be X.509");
        byte[] encoded1 = p1.getEncoded();

        X509EncodedKeySpec spec1 = new X509EncodedKeySpec(encoded1);
        PublicKey p2 = encodedKF.generatePublic(spec1);
        harness.check(p1.equals(p2), "Two DSS public keys MUST be equal");

        PrivateKey p3 = kp.getPrivate();
View Full Code Here

        String f1 = p1.getFormat();
        harness.check("X.509".equalsIgnoreCase(f1),
                      "RSA public key format MUST be X.509");
        byte[] encoded1 = p1.getEncoded();

        X509EncodedKeySpec spec1 = new X509EncodedKeySpec(encoded1);
        PublicKey p2 = encodedKF.generatePublic(spec1);
        harness.check(p1.equals(p2), "Two RSA public keys MUST be equal");

        PrivateKey p3 = kp.getPrivate();
View Full Code Here

        String f1 = p1.getFormat();
        harness.check("X.509".equalsIgnoreCase(f1),
                      "DH public key format MUST be X.509");
        byte[] encoded1 = p1.getEncoded();

        X509EncodedKeySpec spec1 = new X509EncodedKeySpec(encoded1);
        PublicKey p2 = encodedKF.generatePublic(spec1);
        harness.check(p1.equals(p2), "Two DH public keys MUST be equal");

        PrivateKey p3 = kp.getPrivate();
View Full Code Here

TOP

Related Classes of java.security.spec.X509EncodedKeySpec

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.