Java Code Examples for java.security.NoSuchAlgorithmException#getCause()

The following examples show how to use java.security.NoSuchAlgorithmException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenerateKeyImpl.java    From julongchain with Apache License 2.0 6 votes vote down vote up
public IKey genAESKey(int size) throws CspException{

        try {
            //1.构造密钥生成器,指定为AES算法,不区分大小写
            KeyGenerator keygen = KeyGenerator.getInstance("AES");
            //2.根据ecnodeRules规则初始化密钥生成器
            //生成一个128位的随机源,根据传入的字节数组
            SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
            random.setSeed(encodeRules.getBytes());
            keygen.init(size, random);
            //3.产生原始对称密钥
            SecretKey key = keygen.generateKey();

            MessageDigest shahash = MessageDigest.getInstance("SHA-1");
            shahash.update(key.getEncoded());
            byte[] bytehash = shahash.digest();
            SymmetryKey.AESPriKey aeskey = new SymmetryKey.AESPriKey(key.getEncoded(), null, true);
            return aeskey;

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            String err = String.format("[JC_PKCS_SOFT]:NoSuchAlgorithmException ErrMessage: %s", e.getMessage());
            throw new CspException(err, e.getCause());
        }
    }
 
Example 2
Source File: CertStore.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
private static CertStore handleException(NoSuchAlgorithmException e)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    Throwable cause = e.getCause();
    if (cause instanceof InvalidAlgorithmParameterException) {
        throw (InvalidAlgorithmParameterException)cause;
    }
    throw e;
}
 
Example 3
Source File: CertStore.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static CertStore handleException(NoSuchAlgorithmException e)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    Throwable cause = e.getCause();
    if (cause instanceof InvalidAlgorithmParameterException) {
        throw (InvalidAlgorithmParameterException)cause;
    }
    throw e;
}
 
Example 4
Source File: Configuration.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static Configuration handleException(NoSuchAlgorithmException nsae)
            throws NoSuchAlgorithmException {
    Throwable cause = nsae.getCause();
    if (cause instanceof IllegalArgumentException) {
        throw (IllegalArgumentException)cause;
    }
    throw nsae;
}
 
Example 5
Source File: Utils.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
    setLibrary(args);

    try {
        TerminalFactory factory = (provider == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provider);
        System.out.println(factory);

        List<CardTerminal> terminals = factory.terminals().list();
        System.out.println("Terminals: " + terminals);
        if (terminals.isEmpty()) {
            return null;
        }
        CardTerminal terminal = terminals.get(0);

        if (terminal.isCardPresent() == false) {
            System.out.println("*** Insert card");
            if (terminal.waitForCardPresent(20 * 1000) == false) {
                throw new Exception("no card available");
            }
        }
        System.out.println("card present: " + terminal.isCardPresent());

        return terminal;

    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 6
Source File: Utils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
    setLibrary(args);

    try {
        TerminalFactory factory = (provider == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provider);
        System.out.println(factory);

        List<CardTerminal> terminals = factory.terminals().list();
        System.out.println("Terminals: " + terminals);
        if (terminals.isEmpty()) {
            return null;
        }
        CardTerminal terminal = terminals.get(0);

        if (terminal.isCardPresent() == false) {
            System.out.println("*** Insert card");
            if (terminal.waitForCardPresent(20 * 1000) == false) {
                throw new Exception("no card available");
            }
        }
        System.out.println("card present: " + terminal.isCardPresent());

        return terminal;

    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 7
Source File: CertStore.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static CertStore handleException(NoSuchAlgorithmException e)
        throws NoSuchAlgorithmException,
        InvalidAlgorithmParameterException {
    Throwable cause = e.getCause();
    if (cause instanceof InvalidAlgorithmParameterException) {
        throw (InvalidAlgorithmParameterException)cause;
    }
    throw e;
}
 
Example 8
Source File: TestChunking.java    From staash with Apache License 2.0 5 votes vote down vote up
public boolean compareMD5(byte[] written, byte[] read) {
	try {
		MessageDigest md = MessageDigest.getInstance(ENC1);
		byte[] wdigest = md.digest(written);
		byte[] rdigest = md.digest(read);
		return Arrays.equals(wdigest, rdigest);
	} catch (NoSuchAlgorithmException e) {
		// TODO Auto-generated catch block
		throw new RuntimeException(e.getCause());
	}
}
 
Example 9
Source File: CertStore.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static CertStore handleException(NoSuchAlgorithmException e)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    Throwable cause = e.getCause();
    if (cause instanceof InvalidAlgorithmParameterException) {
        throw (InvalidAlgorithmParameterException)cause;
    }
    throw e;
}
 
Example 10
Source File: CertStore.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static CertStore handleException(NoSuchAlgorithmException e)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    Throwable cause = e.getCause();
    if (cause instanceof InvalidAlgorithmParameterException) {
        throw (InvalidAlgorithmParameterException)cause;
    }
    throw e;
}
 
Example 11
Source File: CertStore.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private static CertStore handleException(NoSuchAlgorithmException e)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    Throwable cause = e.getCause();
    if (cause instanceof InvalidAlgorithmParameterException) {
        throw (InvalidAlgorithmParameterException)cause;
    }
    throw e;
}
 
Example 12
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
    setLibrary(args);

    try {
        TerminalFactory factory = (provider == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provider);
        System.out.println(factory);

        List<CardTerminal> terminals = factory.terminals().list();
        System.out.println("Terminals: " + terminals);
        if (terminals.isEmpty()) {
            return null;
        }
        CardTerminal terminal = terminals.get(0);

        if (terminal.isCardPresent() == false) {
            System.out.println("*** Insert card");
            if (terminal.waitForCardPresent(20 * 1000) == false) {
                throw new Exception("no card available");
            }
        }
        System.out.println("card present: " + terminal.isCardPresent());

        return terminal;

    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 13
Source File: Utils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static TerminalFactory getTerminalFactory(String provName) throws Exception {
    try {
        TerminalFactory factory = (provName == null)
                ? TerminalFactory.getInstance("PC/SC", null)
                : TerminalFactory.getInstance("PC/SC", null, provName);
        System.out.println(factory);
        return factory;
    } catch (NoSuchAlgorithmException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
            return null;
        }
        throw e;
    }
}
 
Example 14
Source File: Configuration.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Configuration handleException(NoSuchAlgorithmException nsae)
            throws NoSuchAlgorithmException {
    Throwable cause = nsae.getCause();
    if (cause instanceof IllegalArgumentException) {
        throw (IllegalArgumentException)cause;
    }
    throw nsae;
}
 
Example 15
Source File: CertStore.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static CertStore handleException(NoSuchAlgorithmException e)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    Throwable cause = e.getCause();
    if (cause instanceof InvalidAlgorithmParameterException) {
        throw (InvalidAlgorithmParameterException)cause;
    }
    throw e;
}
 
Example 16
Source File: CertStore.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private static CertStore handleException(NoSuchAlgorithmException e)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    Throwable cause = e.getCause();
    if (cause instanceof InvalidAlgorithmParameterException) {
        throw (InvalidAlgorithmParameterException)cause;
    }
    throw e;
}
 
Example 17
Source File: CertStore.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static CertStore handleException(NoSuchAlgorithmException e)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    Throwable cause = e.getCause();
    if (cause instanceof InvalidAlgorithmParameterException) {
        throw (InvalidAlgorithmParameterException)cause;
    }
    throw e;
}
 
Example 18
Source File: Configuration.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Configuration handleException(NoSuchAlgorithmException nsae)
            throws NoSuchAlgorithmException {
    Throwable cause = nsae.getCause();
    if (cause instanceof IllegalArgumentException) {
        throw (IllegalArgumentException)cause;
    }
    throw nsae;
}
 
Example 19
Source File: Configuration.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private static Configuration handleException(NoSuchAlgorithmException nsae)
            throws NoSuchAlgorithmException {
    Throwable cause = nsae.getCause();
    if (cause instanceof IllegalArgumentException) {
        throw (IllegalArgumentException)cause;
    }
    throw nsae;
}
 
Example 20
Source File: EbicsUtils.java    From axelor-open-suite with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Generates a random nonce.
 *
 * <p>EBICS Specification 2.4.2 - 11.6 Generation of the transaction IDs:
 *
 * <p>Transaction IDs are cryptographically-strong random numbers with a length of 128 bits. This
 * means that the likelihood of any two bank systems using the same transaction ID at the same
 * time is sufficiently small.
 *
 * <p>Transaction IDs are generated by cryptographic pseudo-random number generators (PRNG) that
 * have been initialized with a real random number (seed). The entropy of the seed should be at
 * least 100 bits.
 *
 * @return a random nonce.
 * @throws EbicsException nonce generation fails.
 */
public static byte[] generateNonce() throws AxelorException {
  SecureRandom secureRandom;

  try {
    secureRandom = SecureRandom.getInstance("SHA1PRNG");
    return secureRandom.generateSeed(16);
  } catch (NoSuchAlgorithmException e) {
    throw new AxelorException(e.getCause(), TraceBackRepository.TYPE_FUNCTIONNAL, e.getMessage());
  }
}