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:edu.indiana.d2i.sloan.ui.LoginSuccessAction.java

private boolean disableSSL() {
    // Create empty HostnameVerifier
    HostnameVerifier hv = new HostnameVerifier() {
        public boolean verify(String urlHostName, SSLSession session) {
            return true;
        }/*from   w w w.jav  a 2s  .  com*/
    };

    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
        }

        public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
        }
    } };

    // install all-trust manager
    try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        SSLSocketFactory sslSocketFactory = sc.getSocketFactory();
        HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
        HttpsURLConnection.setDefaultHostnameVerifier(hv);
        return true;
    } catch (NoSuchAlgorithmException e) {
        logger.error(e.getMessage(), e);
        addActionError(e.getMessage());
        return false;
    } catch (KeyManagementException e) {
        logger.error(e.getMessage(), e);
        addActionError(e.getMessage());
        return false;
    }
}

From source file:org.riksa.syncmute.ParseTools.java

/**
 * Get channel name. Channel name is a salted SHA-256 hash of username+channename (from settings)
 *
 * @return Base64 encoded SHA-256 salted hash
 *///  w w  w .j  a va2s  .c o m
protected String getChannel() {
    try {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        String userName = preferences.getString("preferences_username", "DEFAULT");
        String channelName = preferences.getString("preferences_channel", "DEFAULT");
        Log.d(TAG, "hashing username=" + userName);
        Log.d(TAG, "hashing channelName=" + channelName);

        byte[] digest = doHash(DIGEST_ALGORITHM, SALT, userName.getBytes("UTF-8"),
                channelName.getBytes("UTF-8"));
        // Base64 encode without padding. Padded channel name is invalid (alphanumerics only)
        String base64Digest = Base64.encodeToString(digest, Base64.NO_WRAP | Base64.NO_PADDING);
        Log.d(TAG, "base64Digest=" + base64Digest);

        return base64Digest;
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, e.getMessage(), e);
    }
    return "DEFAULT";
}

From source file:netinf.common.security.impl.CryptoAlgorithmImpl.java

@Override
public String encrypt(String algorithm, Key key, String unencrypted) throws NetInfCheckedSecurityException {
    try {/*from   w ww. j  a  v  a  2  s.com*/
        LOG.debug("Encrypting string.");
        LOG.trace("Used algorithm: " + algorithm);
        LOG.trace("Used key: " + key);
        LOG.trace("Used string: " + unencrypted);
        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        byte[] unencryptedBytes = Utils.stringToBytes(unencrypted);
        byte[] encryptedBytes = cipher.doFinal(unencryptedBytes);
        return Base64.encodeBase64String(encryptedBytes);
    } catch (NoSuchAlgorithmException e) {
        throw new NetInfCheckedSecurityException("Unknown cipher-algorithm: " + e.getMessage());
    } catch (NoSuchPaddingException e) {
        throw new NetInfCheckedSecurityException("Unknown cipher-padding: " + e.getMessage());
    } catch (InvalidKeyException e) {
        throw new NetInfCheckedSecurityException("Invalid Key. " + e.getMessage());
    } catch (IllegalBlockSizeException e) {
        throw new NetInfCheckedSecurityException("Illegal cipher-block-size: " + e.getMessage());
    } catch (BadPaddingException e) {
        throw new NetInfCheckedSecurityException("Bad cipher-padding: " + e.getMessage());
    }
}

From source file:org.apache.archiva.checksum.Checksum.java

public Checksum(ChecksumAlgorithm checksumAlgorithm) {
    this.checksumAlgorithm = checksumAlgorithm;
    try {//from  ww w.j  a v  a  2  s. co m
        md = MessageDigest.getInstance(checksumAlgorithm.getAlgorithm());
    } catch (NoSuchAlgorithmException e) {
        // Not really possible, but here none-the-less
        throw new IllegalStateException("Unable to initialize MessageDigest algorithm "
                + checksumAlgorithm.getAlgorithm() + " : " + e.getMessage(), e);
    }
}

From source file:client.communication.ClientRequest.java

public Player login(String username, String password) {
    socket = new SocketClient();

    MessageDigest md = null;/*from www  .ja v a 2 s  .  c  o  m*/

    String passwordHash = "";

    // Gera o hash md5 da senha digitada pelo usurio
    try {
        md = MessageDigest.getInstance("MD5");
        md.update(password.getBytes());

        passwordHash = Hex.encodeHexString(md.digest());
    } catch (NoSuchAlgorithmException e) {
        System.err.println(this.getClass().getName() + ": " + e.getMessage());
    }

    request = makeRequest(Request.LOGIN, username + " " + passwordHash);

    //        System.out.println("Serialized Object Size: " + q.length());
    //        System.out.println("Deserialize: " + q);

    reply = socket.sendMessage(request);

    if (reply.equals(Reply.FAIL.toString())) {
        return null;
    } else {
        // Deserializa objeto
        Gson gson = new Gson();
        player = gson.fromJson(reply, Player.class);
    }

    socket = null;

    return player;
}

From source file:netinf.common.security.impl.CryptoAlgorithmImpl.java

@Override
public String decrypt(String algorithm, Key key, String encrypted) throws NetInfCheckedSecurityException {
    try {/*from w  ww .ja va 2  s  .  co  m*/
        LOG.debug("Decrypting string.");
        LOG.trace("Used algorithm: " + algorithm);
        LOG.trace("Used key: " + key);
        LOG.trace("Used string: " + encrypted);
        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(Cipher.DECRYPT_MODE, key);
        byte[] encryptedBytes = Base64.decodeBase64(encrypted);
        LOG.trace("Encrypted bytes: " + Utils.bytesToString(encryptedBytes));
        byte[] unencryptedBytes = cipher.doFinal(encryptedBytes);
        LOG.trace("Unencrypted bytes: " + Utils.bytesToString(unencryptedBytes));
        String unencryptedString = Utils.bytesToString(unencryptedBytes);
        LOG.trace("Unencrypted String: " + unencryptedString);
        return unencryptedString;
    } catch (NoSuchAlgorithmException e) {
        throw new NetInfCheckedSecurityException("Unknown cipher-algorithm. " + e.getMessage());
    } catch (NoSuchPaddingException e) {
        throw new NetInfCheckedSecurityException("Unknown cipher-padding. " + e.getMessage());
    } catch (InvalidKeyException e) {
        throw new NetInfCheckedSecurityException("Invalid Key. " + e.getMessage());
    } catch (IllegalBlockSizeException e) {
        throw new NetInfCheckedSecurityException("Illegal cipher-block-size. " + e.getMessage());
    } catch (BadPaddingException e) {
        throw new NetInfCheckedSecurityException("Bad cipher-padding. " + e.getMessage());
    }
}

From source file:uk.bl.wa.hadoop.datasets.WARCDatasetMapper.java

public void innerConfigure(Config jobConfig) {
    try {//from ww w  . j  a  va 2s . com
        // 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);
        }

        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:it.jnrpe.server.CBindingThread.java

/**
 * Returns the SSL factory to be used to create the Server Socket
 * @throws KeyStoreException //from   w  ww.  j a v  a  2s .c o  m
 * @throws IOException 
 * @throws FileNotFoundException 
 * @throws CertificateException 
 * @throws UnrecoverableKeyException 
 * @throws KeyManagementException 
 * 
 * @see it.intesa.fi2.client.network.ISSLObjectsFactory#getSSLSocketFactory(String, String, String)
 */
public SSLServerSocketFactory getSSLSocketFactory(String sKeyStoreFile, String sKeyStorePwd,
        String sKeyStoreType) throws KeyStoreException, CertificateException, FileNotFoundException,
        IOException, UnrecoverableKeyException, KeyManagementException {
    if (sKeyStoreFile == null)
        throw new KeyStoreException("KEYSTORE HAS NOT BEEN SPECIFIED");
    if (this.getClass().getClassLoader().getResourceAsStream(sKeyStoreFile) == null)
        throw new KeyStoreException("COULD NOT FIND KEYSTORE '" + sKeyStoreFile + "'");

    if (sKeyStorePwd == null)
        throw new KeyStoreException("KEYSTORE PASSWORD HAS NOT BEEN SPECIFIED");

    SSLContext ctx;
    KeyManagerFactory kmf;

    try {
        ctx = SSLContext.getInstance("SSLv3");

        kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());

        //KeyStore ks = getKeystore(sKeyStoreFile, sKeyStorePwd, sKeyStoreType);
        KeyStore ks = KeyStore.getInstance(sKeyStoreType);
        ks.load(this.getClass().getClassLoader().getResourceAsStream(sKeyStoreFile),
                sKeyStorePwd.toCharArray());

        char[] passphrase = sKeyStorePwd.toCharArray();
        kmf.init(ks, passphrase);
        ctx.init(kmf.getKeyManagers(), null, new java.security.SecureRandom());

    } catch (NoSuchAlgorithmException e) {
        throw new SSLException("Unable to initialize SSLSocketFactory.\n" + e.getMessage());
    }

    return ctx.getServerSocketFactory();
}

From source file:io.kodokojo.bdd.stage.ApplicationWhen.java

public SELF createProjectConfiguration(String projectName, StackConfigDto stackConfigDto) {
    if (isBlank(projectName)) {
        throw new IllegalArgumentException("projectName must be defined.");
    }//w  w  w . j a va  2s.  c o m
    //  Mock behavior
    BootstrapStackData boostrapData = new BootstrapStackData(projectName, "build-A", "127.0.0.1", 10022);
    Mockito.when(projectManager.bootstrapStack(projectName, "build-A", StackType.BUILD))
            .thenReturn(boostrapData);
    KeyPair keyPair = null;
    try {
        keyPair = RSAUtils.generateRsaKeyPair();
    } catch (NoSuchAlgorithmException e) {
        fail(e.getMessage());
    }
    Set<Stack> stacks = new HashSet<>();
    stacks.add(new Stack("build-A", StackType.BUILD, new HashSet<BrickState>()));
    Project project = new Project("1234567890", projectName, new Date(), stacks);
    try {
        Mockito.when(projectManager.start(Mockito.any())).thenReturn(project);
    } catch (ProjectAlreadyExistException e) {
        fail(e.getMessage());
    }

    projectConfigurationId = httpUserSupport.createProjectConfiguration(projectName, stackConfigDto,
            currentUsers.get(currentUserLogin));

    String projectConfiguration = getProjectConfiguration(currentUserLogin, projectConfigurationId);
    currentStep.addAttachment(
            Attachment.plainText(projectConfiguration).withTitle("Project configuration for " + projectName)
                    .withFileName("projectconfiguration_" + projectName + ".json"));

    return self();
}

From source file:org.apache.cloudstack.storage.datastore.util.NexentaNmsClient.java

protected DefaultHttpClient getHttpsClient() {
    try {/*from  w  w w  .  j  av  a  2s .  c om*/
        SSLContext sslContext = SSLUtils.getSSLContext();
        X509TrustManager tm = new X509TrustManager() {
            @Override
            public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
            }

            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        };

        sslContext.init(null, new TrustManager[] { tm }, new SecureRandom());

        SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext,
                SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        SchemeRegistry registry = new SchemeRegistry();

        registry.register(new Scheme("https", nmsUrl.getPort(), socketFactory));

        BasicClientConnectionManager mgr = new BasicClientConnectionManager(registry);

        return new DefaultHttpClient(mgr);
    } catch (NoSuchAlgorithmException ex) {
        throw new CloudRuntimeException(ex.getMessage());
    } catch (KeyManagementException ex) {
        throw new CloudRuntimeException(ex.getMessage());
    }
}