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:cn.mrdear.pay.util.RSAUtils.java

/**
 * ?//from  w ww .j  a  v a2s. c  o m
 * 
 * @param encodedKey
 *            ?
 * @return 
 */
public static PublicKey generatePublicKey(byte[] encodedKey) {
    Assert.notNull(encodedKey);

    try {
        KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM, PROVIDER);
        return keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (InvalidKeySpecException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:eu.eco2clouds.api.bonfire.client.rest.RestClient.java

private static void enableSSLUnsecureTrustStore() {
    try {// w  w w  .  java2 s. co m
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom());
        SSLContext.setDefault(ctx);
    } catch (NoSuchAlgorithmException exception) {
        System.out.println("ERROR TRYING TO DISSABLE JAVA SSL SECURITY");
        System.out.println("NO TLS ALGORITHM EXCEPTION");
        System.out.println("EXCEPTION" + exception.getMessage());
    } catch (KeyManagementException exception) {
        System.out.println("ERROR TRYING TO DISSABLE JAVA SSL SECURITY");
        System.out.println("KEY MANAGEMENT CREATION EXCEPTION");
        System.out.println("EXCEPTION" + exception.getMessage());
    }
}

From source file:cn.mrdear.pay.util.RSAUtils.java

/**
 * ???//  w  w w  .  j  a  v  a2  s  .co m
 * 
 * @param algorithm
 *            ??
 * @param privateKey
 *            ?
 * @param data
 *            ?
 * @return ??
 */
public static byte[] sign(String algorithm, PrivateKey privateKey, byte[] data) {
    Assert.isNotEmpty(algorithm);
    Assert.notNull(privateKey);
    Assert.notNull(data);

    try {
        Signature signature = Signature.getInstance(algorithm, PROVIDER);
        signature.initSign(privateKey);
        signature.update(data);
        return signature.sign();
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (InvalidKeyException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (SignatureException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.amazonaws.http.HttpClientFactory.java

/**
 * @see SSLContexts#createDefault()//w  ww .j a v a 2 s .c o  m
 */
public static SSLContext createSSLContext(ClientConfiguration config) throws SSLInitializationException {
    try {
        final SSLContext sslcontext = SSLContext.getInstance("TLS");
        // http://download.java.net/jdk9/docs/technotes/guides/security/jsse/JSSERefGuide.html
        sslcontext.init(null, null, config.getSecureRandom());
        return sslcontext;
    } catch (final NoSuchAlgorithmException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    } catch (final KeyManagementException ex) {
        throw new SSLInitializationException(ex.getMessage(), ex);
    }
}

From source file:cn.mrdear.pay.util.RSAUtils.java

/**
 * ???// w  w w .j av a 2 s. c o  m
 * 
 * @param algorithm
 *            ??
 * @param publicKey
 *            
 * @param sign
 *            ??
 * @param data
 *            ?
 * @return ??
 */
public static boolean verify(String algorithm, PublicKey publicKey, byte[] sign, byte[] data) {
    Assert.isNotEmpty(algorithm);
    Assert.notNull(publicKey);
    Assert.notNull(sign);
    Assert.notNull(data);

    try {
        Signature signature = Signature.getInstance(algorithm, PROVIDER);
        signature.initVerify(publicKey);
        signature.update(data);
        return signature.verify(sign);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (InvalidKeyException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (SignatureException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:cn.mrdear.pay.util.RSAUtils.java

/**
 * ???/*w  ww . j  ava  2s.  c o m*/
 * 
 * @param algorithm
 *            ??
 * @param certificate
 *            ?
 * @param sign
 *            ??
 * @param data
 *            ?
 * @return ??
 */
public static boolean verify(String algorithm, Certificate certificate, byte[] sign, byte[] data) {
    Assert.isNotEmpty(algorithm);
    Assert.notNull(certificate);
    Assert.notNull(sign);
    Assert.notNull(data);

    try {
        Signature signature = Signature.getInstance(algorithm, PROVIDER);
        signature.initVerify(certificate);
        signature.update(data);
        return signature.verify(sign);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (InvalidKeyException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (SignatureException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:cn.mrdear.pay.util.RSAUtils.java

/**
 * /*  w  ww. ja v a  2  s  .  c  o m*/
 * 
 * @param publicKey
 *            
 * @param data
 *            ?
 * @return 
 */
public static byte[] encrypt(PublicKey publicKey, byte[] data) {
    Assert.notNull(publicKey);
    Assert.notNull(data);

    try {
        Cipher cipher = Cipher.getInstance(TRANSFORMATION, PROVIDER);
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        return cipher.doFinal(data);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (NoSuchPaddingException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (InvalidKeyException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (IllegalBlockSizeException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (BadPaddingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:cn.mrdear.pay.util.RSAUtils.java

/**
 * //from   w ww.  ja v a  2  s.c om
 * 
 * @param privateKey
 *            ?
 * @param data
 *            ?
 * @return 
 */
public static byte[] decrypt(PrivateKey privateKey, byte[] data) {
    Assert.notNull(privateKey);
    Assert.notNull(data);

    try {
        Cipher cipher = Cipher.getInstance(TRANSFORMATION, PROVIDER);
        cipher.init(Cipher.DECRYPT_MODE, privateKey);
        return cipher.doFinal(data);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (NoSuchPaddingException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (InvalidKeyException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (IllegalBlockSizeException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (BadPaddingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:net.sourceforge.jaulp.file.checksum.ChecksumUtils.java

/**
 * Gets the checksum quietly from the given byte array with an instance of.
 *
 * @param bytes//w  ww  .  j  a  v  a2 s  .co  m
 *            the byte array.
 * @param algorithm
 *            the algorithm to get the checksum. This could be for instance "MD4", "MD5",
 *            "SHA-1", "SHA-256", "SHA-384" or "SHA-512".
 * @return The checksum from the file as a String object.
 */
public static String getChecksumQuietly(byte[] bytes, Algorithm algorithm) {
    try {
        return getChecksum(bytes, algorithm.getAlgorithm());
    } catch (NoSuchAlgorithmException e) {
        LOGGER.error("getChecksumQuietly failed...\n" + e.getMessage(), e);
    }
    return null;
}

From source file:net.sourceforge.jaulp.file.checksum.ChecksumUtils.java

/**
 * Gets the checksum quietly from the given file with an instance of the given algorithm.
 *
 * @param file// w w w .  j a  v a 2 s . c  om
 *            the file.
 * @param algorithm
 *            the algorithm to get the checksum. This could be for instance "MD4", "MD5",
 *            "SHA-1", "SHA-256", "SHA-384" or "SHA-512".
 * @return The checksum from the file as a String object or null if a NoSuchAlgorithmException
 *         will be thrown. exists. {@link java.security.MessageDigest} object.
 */
public static String getChecksumQuietly(File file, Algorithm algorithm) {
    try {
        return getChecksum(file, algorithm.getAlgorithm());
    } catch (NoSuchAlgorithmException e) {
        LOGGER.error("getChecksumQuietly failed...\n" + e.getMessage(), e);
    }
    return null;
}