Example usage for java.security NoSuchAlgorithmException getMessage

List of usage examples for java.security NoSuchAlgorithmException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:uk.bl.wa.hadoop.indexer.WARCIndexerMapper.java

public void innerConfigure(Config jobConfig) {
    try {/*w w w. j  a v a2  s  .c  om*/
        // Get config from job property:
        config = jobConfig;
        // Initialise indexer:
        this.windex = new WARCIndexer(config);
        // Decide whether to try to apply annotations:
        boolean applyAnnotations = false;
        if (config.hasPath(WARCIndexerRunner.CONFIG_APPLY_ANNOTATIONS)) {
            applyAnnotations = config.getBoolean(WARCIndexerRunner.CONFIG_APPLY_ANNOTATIONS);
        }
        if (applyAnnotations) {
            LOG.info("Attempting to load annotations from 'annotations.json'...");
            Annotations ann = Annotations.fromJsonFile("annotations.json");
            LOG.info("Attempting to load OA SURTS from 'openAccessSurts.txt'...");
            SurtPrefixSet oaSurts = Annotator.loadSurtPrefix("openAccessSurts.txt");
            windex.setAnnotations(ann, oaSurts);
        }

        // Set up sharding:
        numShards = config.getInt(SolrWebServer.NUM_SHARDS);

        // Get the number of reducers:
        try {
            numReducers = config.getInt("warc.hadoop.num_reducers");
        } catch (NumberFormatException n) {
            numReducers = 10;
        }
        solrFactory = SolrRecordFactory.createFactory(config);
    } catch (NoSuchAlgorithmException e) {
        LOG.error("WARCIndexerMapper.configure(): " + e.getMessage());
    } catch (JsonParseException e) {
        LOG.error("WARCIndexerMapper.configure(): " + e.getMessage());
    } catch (JsonMappingException e) {
        LOG.error("WARCIndexerMapper.configure(): " + e.getMessage());
    } catch (IOException e) {
        LOG.error("WARCIndexerMapper.configure(): " + e.getMessage());
    }
}

From source file:com.torchmind.authenticator.AbstractTokenGenerator.java

/**
 * {@inheritDoc}/*from w  w  w. ja  v a  2  s. c  om*/
 */
@NonNull
@Override
public SecretKey generateSecret() {
    try {
        KeyGenerator generator = KeyGenerator.getInstance("Hmac" + this.algorithm.name());
        generator.init(80);
        return generator.generateKey();
    } catch (NoSuchAlgorithmException ex) {
        throw new UnsupportedOperationException(
                "The specified algorithm is not supported by this Java VM implementation: " + ex.getMessage(),
                ex);
    }
}

From source file:org.hdiv.util.EncodingUtil.java

/**
 * Initialize the EncodingUtil with Http Session and message resource.
 *///from  w w w  .  ja v  a  2  s. c  o m
public void init() {

    try {
        this.messageDigest = MessageDigest.getInstance(algorithmName);
    } catch (NoSuchAlgorithmException e) {
        throw new HDIVException(e.getMessage());
    }
}

From source file:eu.eidas.auth.engine.SAMLEngineUtils.java

/**
 * @param cert/*from  w  ww  .j  a v  a 2 s  . co m*/
 * @return true when the certificate is self signed
 */
public static boolean isCertificateSelfSigned(X509Certificate cert) {
    try {
        PublicKey publicKey = cert.getPublicKey();
        cert.verify(publicKey);
        return true;
    } catch (java.security.SignatureException sigEx) {
        LOG.info("ERROR : SignatureException {}", sigEx.getMessage());
        LOG.debug("ERROR : SignatureException {}", sigEx);
        return false;
    } catch (InvalidKeyException keyEx) {
        // Invalid key --> not self-signed
        LOG.info("ERROR : InvalidKeyException {}", keyEx.getMessage());
        LOG.debug("ERROR : InvalidKeyException {}", keyEx);
        return false;
    } catch (CertificateException certExc) {
        LOG.info("ERROR : CertificateException {}", certExc.getMessage());
        LOG.debug("ERROR : CertificateException {}", certExc);
        return false;
    } catch (NoSuchAlgorithmException nsaExc) {
        LOG.info("ERROR : Bad algorithm: " + nsaExc.getMessage());
        LOG.debug("ERROR : Bad algorithm: " + nsaExc);
        return false;
    } catch (NoSuchProviderException nspExc) {
        LOG.info("ERROR : Bad provider: " + nspExc.getMessage());
        LOG.debug("ERROR : Bad provider: " + nspExc);
        return false;
    }
}

From source file:org.opensafety.hishare.util.implementation.EncryptionImpl.java

public byte[] createSalt() throws CryptographyException {
    SecureRandom random;/*  w w  w.  ja  va 2s.  co m*/
    try {
        random = SecureRandom.getInstance(randomAlgorithm);
    } catch (NoSuchAlgorithmException e) {
        throw new CryptographyException(e.getMessage());
    }

    byte[] salt = new byte[saltLength];
    random.nextBytes(salt);

    return salt;
}

From source file:org.opensafety.hishare.util.implementation.EncryptionImpl.java

public String createPassword() throws CryptographyException {
    KeyGenerator kgen;/*from  w  w w . j av a2  s.  c o  m*/
    try {
        kgen = KeyGenerator.getInstance(keyGenerator);
    } catch (NoSuchAlgorithmException e) {
        throw new CryptographyException(e.getMessage());
    }

    kgen.init(passwordLength);

    SecretKey skey = kgen.generateKey();
    byte[] raw = skey.getEncoded();

    return new String(Hex.encodeHex(raw));
}

From source file:org.elasticsearch.hadoop.rest.commonshttp.SSLSocketFactory.java

private SSLContext createSSLContext() {
    SSLContext ctx;//from   ww w .ja v a2  s .  co  m
    try {
        ctx = SSLContext.getInstance(sslProtocol);
    } catch (NoSuchAlgorithmException ex) {
        throw new EsHadoopIllegalStateException("Cannot instantiate SSL - " + ex.getMessage(), ex);
    }
    try {
        ctx.init(loadKeyManagers(), loadTrustManagers(), null);
    } catch (Exception ex) {
        throw new EsHadoopIllegalStateException("Cannot initialize SSL - " + ex.getMessage(), ex);
    }

    return ctx;
}

From source file:org.opensafety.hishare.util.implementation.EncryptionImpl.java

private SecretKey generateKey(String password, byte[] salt) throws CryptographyException {
    PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(), salt, pbeIterationCount, pbeKeyLength);

    SecretKeyFactory factory;/*  ww  w  .j  a v a  2s.  c o m*/
    SecretKey tmp;
    try {
        factory = SecretKeyFactory.getInstance(pbeAlgorithm);
        tmp = factory.generateSecret(pbeKeySpec);
    } catch (NoSuchAlgorithmException e) {
        throw new CryptographyException(e.getMessage());
    } catch (InvalidKeySpecException e) {
        throw new CryptographyException(e.getMessage());
    }

    SecretKey secret = new SecretKeySpec(tmp.getEncoded(), keyGenerator);

    return secret;
}

From source file:com.sk89q.craftapi.streaming.StreamingServerClient.java

/**
 * Handle unauthenticated packets./*from   www . j av a 2 s  .  c o m*/
 * 
 * @param parts
 */
public void handleUnauthenticated(String[] parts) throws UnsupportedEncodingException {
    String command = decode(parts[0]);

    // getChallenge
    if (command.equals("REQC")) {
        send("CHAL", base64.encodeToString(challenge));

        // challengeLogin
    } else if (command.equals("AUTH")) {
        try {
            SecretKey key = new SecretKeySpec(challenge, "HMACSHA256");
            Mac mac = Mac.getInstance("HMACSHA256");
            mac.init(key);
            byte[] digest = base64.decode(decode(parts[3]).getBytes());
            if (server.getAuthenticationProvider().verifyCredentials(mac, parts[2], digest)) {
                send("AUTHOK");
                state = State.READY;
            } else {
                sendError(ERROR_AUTHENTICATION);
            }
        } catch (NoSuchAlgorithmException e) {
            sendError(ERROR_INTERNAL, e.getMessage());
        } catch (InvalidKeyException e) {
            sendError(ERROR_INTERNAL, e.getMessage());
        }

        // Unknown
    } else {
        sendError(ERROR_UNKNOWN_PACKET, command);
    }
}

From source file:com.torchmind.authenticator.AbstractTokenGenerator.java

/**
 * Generates a code based on a secret key and challenge.
 *
 * @param secretKey a secret key.//from  w w  w.j a v a 2s  . co  m
 * @param challenge a challenge.
 * @return a code.
 */
@NonNull
protected String generateCode(@NonNull SecretKey secretKey, @NonNull byte[] challenge) {
    try {
        Mac mac = Mac.getInstance("Hmac" + this.algorithm.name());
        mac.init(secretKey);

        byte[] hash = mac.doFinal(challenge);
        int offset = hash[hash.length - 1] & 0x0F;

        ByteBuffer buffer = ByteBuffer.allocate(4).put(hash, offset, 4);
        buffer.flip();

        return String.format("%0" + this.digits + "d", (buffer.getInt() & 0x7FFFFFFF) % this.digitModulo);
    } catch (NoSuchAlgorithmException ex) {
        throw new UnsupportedOperationException(
                "The specified algorithm is not supported by this Java VM implementation: " + ex.getMessage(),
                ex);
    } catch (InvalidKeyException ex) {
        throw new IllegalArgumentException("Invalid shared secret: " + ex.getMessage(), ex);
    }
}