Example usage for java.security NoSuchAlgorithmException NoSuchAlgorithmException

List of usage examples for java.security NoSuchAlgorithmException NoSuchAlgorithmException

Introduction

In this page you can find the example usage for java.security NoSuchAlgorithmException NoSuchAlgorithmException.

Prototype

public NoSuchAlgorithmException(Throwable cause) 

Source Link

Document

Creates a NoSuchAlgorithmException with the specified cause and a detail message of (cause==null ?

Usage

From source file:Main.java

static String getAlgorithmForOid(String oid) throws NoSuchAlgorithmException {
    if ("1.2.840.10045.2.1".equals(oid)) {
        return "EC";
    } else if ("1.2.840.113549.1.1.1".equals(oid)) {
        return "RSA";
    } else if ("1.2.840.10040.4.1".equals(oid)) {
        return "DSA";
    } else {//from   w  w  w  .  jav a2 s  . com
        throw new NoSuchAlgorithmException("Unknown algorithm OID " + oid);
    }
}

From source file:com.microsoft.tfs.core.config.httpclient.internal.SelfSignedX509TrustManager.java

/**
 * Creates a trust manager capable of accepting self-signed certificates.
 *
 * @param keyStore/*from   w  w w.java  2 s.c  o  m*/
 *        The {@link KeyStore} to use for user-specified keys (or
 *        <code>null</code>)
 * @throws NoSuchAlgorithmException
 * @throws KeyStoreException
 */
public SelfSignedX509TrustManager(final KeyStore keyStore) throws NoSuchAlgorithmException, KeyStoreException {
    final TrustManagerFactory factory = TrustManagerFactory
            .getInstance(TrustManagerFactory.getDefaultAlgorithm());
    factory.init(keyStore);
    final TrustManager[] trustManagers = factory.getTrustManagers();

    if (trustManagers.length == 0) {
        throw new NoSuchAlgorithmException("No trust manager found"); //$NON-NLS-1$
    }

    if (!(trustManagers[0] instanceof X509TrustManager)) {
        throw new NoSuchAlgorithmException("No X509 trust manager found"); //$NON-NLS-1$
    }

    standardTrustManager = (X509TrustManager) trustManagers[0];
}

From source file:com.cazoodle.crawl.DummyX509TrustManager.java

/**
 * Constructor for DummyX509TrustManager.
 *//*w w w . j  a  va 2s.  co  m*/
public DummyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
    super();
    TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509");
    factory.init(keystore);
    TrustManager[] trustmanagers = factory.getTrustManagers();
    if (trustmanagers.length == 0) {
        throw new NoSuchAlgorithmException("SunX509 trust manager not supported");
    }
    this.standardTrustManager = (X509TrustManager) trustmanagers[0];
}

From source file:com.iflytek.spider.protocol.httpclient.DummyX509TrustManager.java

/**
 * Constructor for DummyX509TrustManager.
 *///  w ww .  j a va  2  s. c  o  m
public DummyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
    super();
    String algo = TrustManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory factory = TrustManagerFactory.getInstance(algo);
    factory.init(keystore);
    TrustManager[] trustmanagers = factory.getTrustManagers();
    if (trustmanagers.length == 0) {
        throw new NoSuchAlgorithmException(algo + " trust manager not supported");
    }
    this.standardTrustManager = (X509TrustManager) trustmanagers[0];
}

From source file:com.manning.androidhacks.hack023.net.SimpleX509TrustManager.java

public SimpleX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
    TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    factory.init(keystore);/* ww w .j  av  a 2 s. c o  m*/
    TrustManager[] trustmanagers = factory.getTrustManagers();
    if (trustmanagers.length == 0) {
        throw new NoSuchAlgorithmException("No trust manager found");
    }
    this.standardTrustManager = (X509TrustManager) trustmanagers[0];
}

From source file:at.gv.egiz.pdfas.lib.util.CertificateUtils.java

public static AlgorithmID[] getAlgorithmIDs(X509Certificate signingCertificate)
        throws NoSuchAlgorithmException {
    PublicKey publicKey = signingCertificate.getPublicKey();
    String algorithm = publicKey.getAlgorithm();
    AlgorithmID[] algorithms = new AlgorithmID[2];
    AlgorithmID signatureAlgorithm;/*from  w  w  w. java 2 s.c om*/
    AlgorithmID digestAlgorithm;

    if ("DSA".equals(algorithm)) {
        signatureAlgorithm = AlgorithmID.dsaWithSHA256;
        digestAlgorithm = AlgorithmID.sha256;
    } else if ("RSA".equals(algorithm)) {
        signatureAlgorithm = AlgorithmID.sha256WithRSAEncryption;
        digestAlgorithm = AlgorithmID.sha256;
    } else if (("EC".equals(algorithm)) || ("ECDSA".equals(algorithm))) {

        int fieldSize = 0;
        if (publicKey instanceof ECPublicKey) {
            ECParameterSpec params = ((ECPublicKey) publicKey).getParams();
            fieldSize = params.getCurve().getField().getFieldSize();
        }

        if (fieldSize >= 512) {
            signatureAlgorithm = AlgorithmID.ecdsa_With_SHA512;
            digestAlgorithm = AlgorithmID.sha512;
        } else if (fieldSize >= 256) {
            signatureAlgorithm = AlgorithmID.ecdsa_With_SHA256;
            digestAlgorithm = AlgorithmID.sha256;
        } else {
            signatureAlgorithm = AlgorithmID.ecdsa_With_SHA1;
            digestAlgorithm = AlgorithmID.sha1;
        }
    } else {
        throw new NoSuchAlgorithmException("Public key algorithm '" + algorithm + "' not supported.");
    }

    algorithms[0] = signatureAlgorithm;
    algorithms[1] = digestAlgorithm;

    return algorithms;
}

From source file:com.fatwire.dta.sscrawler.EasyX509TrustManager.java

/**
 * Constructor for EasyX509TrustManager.
 *///w w w . j ava 2  s.  c  o m
public EasyX509TrustManager(final KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
    super();
    final TrustManagerFactory factory = TrustManagerFactory
            .getInstance(TrustManagerFactory.getDefaultAlgorithm());
    factory.init(keystore);
    final TrustManager[] trustmanagers = factory.getTrustManagers();
    if (trustmanagers.length == 0) {
        throw new NoSuchAlgorithmException("no trust manager found");
    }
    standardTrustManager = (X509TrustManager) trustmanagers[0];
}

From source file:EasyX509TrustManager.java

/**
 * Constructor for EasyX509TrustManager.
 *///  ww w .  j  a v a 2 s  .  c  o  m
public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
    super();
    TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509");
    factory.init(keystore);
    TrustManager[] trustmanagers = factory.getTrustManagers();
    if (trustmanagers.length == 0) {
        throw new NoSuchAlgorithmException("SunX509 trust manager not supported");
    }
    this.standardTrustManager = (X509TrustManager) trustmanagers[0];
}

From source file:egovframework.com.ext.jfile.security.service.CipherServiceImpl.java

/**
 *   ?.//from   ww w  .  j a va 2 s . co m
 * @param keyAlgorithm  .
 * @param algorithm .
 * @param keyData  ??.
 * @return Key  .
 * @throws NoSuchAlgorithmException   ?  ?  .
 * @throws InvalidKeyException  ? key ?  
 * @throws InvalidKeySpecException  ? keySpec ?  
 */
private static Key generateKey(String keyAlgorithm, String algorithm, byte[] keyData)
        throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException {
    if (keyAlgorithm == null || "".equals(keyAlgorithm))
        throw new NoSuchAlgorithmException("algorithm is nessary");
    String upper = keyAlgorithm.toUpperCase();
    if ("DES".equals(upper)) {
        KeySpec keySpec = new DESKeySpec(keyData);
        SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(keyAlgorithm);

        SecretKey secretKey = secretKeyFactory.generateSecret(keySpec);
        return secretKey;

    } else if (upper.indexOf("DESEDE") > -1 || upper.indexOf("TRIPLEDES") > -1) {
        KeySpec keySpec = new DESedeKeySpec(keyData);

        SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(keyAlgorithm);
        SecretKey secretKey = secretKeyFactory.generateSecret(keySpec);
        return secretKey;
    } else {
        SecretKeySpec keySpec = new SecretKeySpec(keyData, keyAlgorithm);
        return keySpec;
    }
}

From source file:ch.truesolutions.payit.https.EasyX509TrustManager.java

/**
 * Constructor for EasyX509TrustManager.
 *///from w w w.  ja v a2 s.c  o  m
public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
    super();
    keyStore = keystore;
    TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509");
    factory.init(keystore);
    TrustManager[] trustmanagers = factory.getTrustManagers();
    if (trustmanagers.length == 0) {
        throw new NoSuchAlgorithmException("SunX509 trust manager not supported");
    }
    this.standardTrustManager = (X509TrustManager) trustmanagers[0];
}