下面列出了java.security.NoSuchAlgorithmException#getCause ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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());
}
}
private static CertStore handleException(NoSuchAlgorithmException e)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
Throwable cause = e.getCause();
if (cause instanceof InvalidAlgorithmParameterException) {
throw (InvalidAlgorithmParameterException)cause;
}
throw e;
}
private static Configuration handleException(NoSuchAlgorithmException nsae)
throws NoSuchAlgorithmException {
Throwable cause = nsae.getCause();
if (cause instanceof IllegalArgumentException) {
throw (IllegalArgumentException)cause;
}
throw nsae;
}
private static Configuration handleException(NoSuchAlgorithmException nsae)
throws NoSuchAlgorithmException {
Throwable cause = nsae.getCause();
if (cause instanceof IllegalArgumentException) {
throw (IllegalArgumentException)cause;
}
throw nsae;
}
private static CertStore handleException(NoSuchAlgorithmException e)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
Throwable cause = e.getCause();
if (cause instanceof InvalidAlgorithmParameterException) {
throw (InvalidAlgorithmParameterException)cause;
}
throw e;
}
private static CertStore handleException(NoSuchAlgorithmException e)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
Throwable cause = e.getCause();
if (cause instanceof InvalidAlgorithmParameterException) {
throw (InvalidAlgorithmParameterException)cause;
}
throw e;
}
private static CertStore handleException(NoSuchAlgorithmException e)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
Throwable cause = e.getCause();
if (cause instanceof InvalidAlgorithmParameterException) {
throw (InvalidAlgorithmParameterException)cause;
}
throw e;
}
private static Configuration handleException(NoSuchAlgorithmException nsae)
throws NoSuchAlgorithmException {
Throwable cause = nsae.getCause();
if (cause instanceof IllegalArgumentException) {
throw (IllegalArgumentException)cause;
}
throw nsae;
}
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;
}
}
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;
}
}
private static CertStore handleException(NoSuchAlgorithmException e)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
Throwable cause = e.getCause();
if (cause instanceof InvalidAlgorithmParameterException) {
throw (InvalidAlgorithmParameterException)cause;
}
throw e;
}
private static CertStore handleException(NoSuchAlgorithmException e)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
Throwable cause = e.getCause();
if (cause instanceof InvalidAlgorithmParameterException) {
throw (InvalidAlgorithmParameterException)cause;
}
throw e;
}
private static CertStore handleException(NoSuchAlgorithmException e)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
Throwable cause = e.getCause();
if (cause instanceof InvalidAlgorithmParameterException) {
throw (InvalidAlgorithmParameterException)cause;
}
throw e;
}
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());
}
}
private static CertStore handleException(NoSuchAlgorithmException e)
throws NoSuchAlgorithmException,
InvalidAlgorithmParameterException {
Throwable cause = e.getCause();
if (cause instanceof InvalidAlgorithmParameterException) {
throw (InvalidAlgorithmParameterException)cause;
}
throw e;
}
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;
}
}
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;
}
}
private static Configuration handleException(NoSuchAlgorithmException nsae)
throws NoSuchAlgorithmException {
Throwable cause = nsae.getCause();
if (cause instanceof IllegalArgumentException) {
throw (IllegalArgumentException)cause;
}
throw nsae;
}
private static CertStore handleException(NoSuchAlgorithmException e)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
Throwable cause = e.getCause();
if (cause instanceof InvalidAlgorithmParameterException) {
throw (InvalidAlgorithmParameterException)cause;
}
throw e;
}
/**
* 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());
}
}