Java Code Examples for java.security.NoSuchAlgorithmException#getMessage()
The following examples show how to use
java.security.NoSuchAlgorithmException#getMessage() .
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: UserService.java From wetech-cms with MIT License | 6 votes |
@Override public User login(String username, String password) { User user = userDao.loadByUsername(username); if (user == null) throw new CmsException("用户名或者密码不正确"); try { if (!SecurityUtil.md5(username, password).equals(user.getPassword())) { throw new CmsException("用户名或者密码不正确"); } } catch (NoSuchAlgorithmException e) { throw new CmsException("密码加密失败:" + e.getMessage()); } if (user.getStatus() == 0) throw new CmsException("用户已经停用,请与管理员联系"); return user; }
Example 2
Source File: DistributedKeyStoreRegistry.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
public KeyStore createDistributedKeyStore(String key, DistributedSignerProxy proxy) throws TechnicalConnectorException { try { KeyStore store = KeyStore.getInstance("DistributedKeyProvider"); Validate.notNull(store); LoadStoreParameter param = new DistributedKeyLoadStoreParam(proxy); store.load(param); if (this.distributedKeyStores.containsKey(key)) { LOG.info("Key [" + key + "] already in cache."); } this.distributedKeyStores.put(key, store); return store; } catch (IOException var5) { throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var5, new Object[]{var5.getMessage()}); } catch (KeyStoreException var6) { throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var6, new Object[]{var6.getMessage()}); } catch (NoSuchAlgorithmException var7) { throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var7, new Object[]{var7.getMessage()}); } catch (CertificateException var8) { throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var8, new Object[]{var8.getMessage()}); } }
Example 3
Source File: X509Store.java From RipplePower with Apache License 2.0 | 5 votes |
public static X509Store getInstance(String type, X509StoreParameters parameters) throws NoSuchStoreException { try { X509Util.Implementation impl = X509Util.getImplementation("X509Store", type); return createStore(impl, parameters); } catch (NoSuchAlgorithmException e) { throw new NoSuchStoreException(e.getMessage()); } }
Example 4
Source File: ConnectorCryptoUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static SecretKey generateKey(String algo, int keySize) throws TechnicalConnectorException { try { if (keyGen == null) { keyGen = KeyGenerator.getInstance(algo); } keyGen.init(keySize, new SecureRandom()); return keyGen.generateKey(); } catch (NoSuchAlgorithmException var3) { throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var3, new Object[]{var3.getMessage()}); } }
Example 5
Source File: AESEncryptCoder.java From onetwo with Apache License 2.0 | 5 votes |
public SecretKey generatedKey(int size){ KeyGenerator keyGenerator = null; try { keyGenerator = KeyGenerator.getInstance(Crypts.AES_KEY); } catch (NoSuchAlgorithmException e) { throw new BaseException("KeyGenerator error: " + e.getMessage() , e); } keyGenerator.init(size); // keyGenerator.init(length); SecretKey skey = keyGenerator.generateKey(); return skey; }
Example 6
Source File: Util.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Compute the "method hash" of a remote method. The method hash * is a long containing the first 64 bits of the SHA digest from * the UTF encoded string of the method name and descriptor. */ public static long computeMethodHash(Method m) { long hash = 0; ByteArrayOutputStream sink = new ByteArrayOutputStream(127); try { MessageDigest md = MessageDigest.getInstance("SHA"); DataOutputStream out = new DataOutputStream( new DigestOutputStream(sink, md)); String s = getMethodNameAndDescriptor(m); if (serverRefLog.isLoggable(Log.VERBOSE)) { serverRefLog.log(Log.VERBOSE, "string used for method hash: \"" + s + "\""); } out.writeUTF(s); // use only the first 64 bits of the digest for the hash out.flush(); byte hasharray[] = md.digest(); for (int i = 0; i < Math.min(8, hasharray.length); i++) { hash += ((long) (hasharray[i] & 0xFF)) << (i * 8); } } catch (IOException ignore) { /* can't happen, but be deterministic anyway. */ hash = -1; } catch (NoSuchAlgorithmException complain) { throw new SecurityException(complain.getMessage()); } return hash; }
Example 7
Source File: Util.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Compute the "method hash" of a remote method. The method hash * is a long containing the first 64 bits of the SHA digest from * the UTF encoded string of the method name and descriptor. */ public static long computeMethodHash(Method m) { long hash = 0; ByteArrayOutputStream sink = new ByteArrayOutputStream(127); try { MessageDigest md = MessageDigest.getInstance("SHA"); DataOutputStream out = new DataOutputStream( new DigestOutputStream(sink, md)); String s = getMethodNameAndDescriptor(m); if (serverRefLog.isLoggable(Log.VERBOSE)) { serverRefLog.log(Log.VERBOSE, "string used for method hash: \"" + s + "\""); } out.writeUTF(s); // use only the first 64 bits of the digest for the hash out.flush(); byte hasharray[] = md.digest(); for (int i = 0; i < Math.min(8, hasharray.length); i++) { hash += ((long) (hasharray[i] & 0xFF)) << (i * 8); } } catch (IOException ignore) { /* can't happen, but be deterministic anyway. */ hash = -1; } catch (NoSuchAlgorithmException complain) { throw new SecurityException(complain.getMessage()); } return hash; }
Example 8
Source File: NoSuchAlgorithmExceptionTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * Test for <code>NoSuchAlgorithmException(Throwable)</code> constructor * Assertion: constructs NoSuchAlgorithmException when <code>cause</code> * is not null */ public void testNoSuchAlgorithmException05() { NoSuchAlgorithmException tE = new NoSuchAlgorithmException(tCause); if (tE.getMessage() != null) { String toS = tCause.toString(); String getM = tE.getMessage(); assertTrue("getMessage() should contain ".concat(toS), (getM .indexOf(toS) != -1)); } assertNotNull("getCause() must not return null", tE.getCause()); assertEquals("getCause() must return ".concat(tCause.toString()), tE .getCause(), tCause); }
Example 9
Source File: Util.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Compute the "method hash" of a remote method. The method hash * is a long containing the first 64 bits of the SHA digest from * the UTF encoded string of the method name and descriptor. */ public static long computeMethodHash(Method m) { long hash = 0; ByteArrayOutputStream sink = new ByteArrayOutputStream(127); try { MessageDigest md = MessageDigest.getInstance("SHA"); DataOutputStream out = new DataOutputStream( new DigestOutputStream(sink, md)); String s = getMethodNameAndDescriptor(m); if (serverRefLog.isLoggable(Log.VERBOSE)) { serverRefLog.log(Log.VERBOSE, "string used for method hash: \"" + s + "\""); } out.writeUTF(s); // use only the first 64 bits of the digest for the hash out.flush(); byte hasharray[] = md.digest(); for (int i = 0; i < Math.min(8, hasharray.length); i++) { hash += ((long) (hasharray[i] & 0xFF)) << (i * 8); } } catch (IOException ignore) { /* can't happen, but be deterministic anyway. */ hash = -1; } catch (NoSuchAlgorithmException complain) { throw new SecurityException(complain.getMessage()); } return hash; }
Example 10
Source File: AesSpillCipher.java From presto with Apache License 2.0 | 5 votes |
private static SecretKey generateNewSecretKey() { try { KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(KEY_BITS); return keyGenerator.generateKey(); } catch (NoSuchAlgorithmException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, "Failed to generate new secret key: " + e.getMessage(), e); } }
Example 11
Source File: XijsonCertprofile.java From xipki with Apache License 2.0 | 5 votes |
private void initBiometricInfo(Set<ASN1ObjectIdentifier> extnIds, Map<String, ExtensionType> extensions) throws CertprofileException { ASN1ObjectIdentifier type = Extension.biometricInfo; if (extensionControls.containsKey(type)) { extnIds.remove(type); BiometricInfo extConf = getExtension(type, extensions).getBiometricInfo(); if (extConf != null) { try { this.biometricInfo = new BiometricInfoOption(extConf); } catch (NoSuchAlgorithmException ex) { throw new CertprofileException("NoSuchAlgorithmException: " + ex.getMessage()); } } } }
Example 12
Source File: MD5GetHandler.java From oodt with Apache License 2.0 | 5 votes |
public MD5GetHandler() throws InstantiationException { try { this.md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { LOG.log(Level.SEVERE, e.getMessage()); throw new InstantiationException(e.getMessage()); } }
Example 13
Source File: ConnectorCryptoUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static SecretKey generateKey(String algo, int keySize) throws TechnicalConnectorException { try { if (keyGen == null) { keyGen = KeyGenerator.getInstance(algo); } keyGen.init(keySize, new SecureRandom()); return keyGen.generateKey(); } catch (NoSuchAlgorithmException var3) { throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_GENERAL, var3, new Object[]{var3.getMessage()}); } }
Example 14
Source File: UserService.java From wetech-cms with MIT License | 5 votes |
@Override public void updatePwd(int uid, String oldPwd, String newPwd) { try { User u = userDao.load(uid); if (!SecurityUtil.md5(u.getUsername(), oldPwd).equals(u.getPassword())) { throw new CmsException("原始密码输入不正确"); } u.setPassword(SecurityUtil.md5(u.getUsername(), newPwd)); userDao.update(u); } catch (NoSuchAlgorithmException e) { throw new CmsException("更新密码失败:" + e.getMessage()); } }
Example 15
Source File: RepositoryManagedSignatureProvider.java From CounterSign with GNU Affero General Public License v3.0 | 5 votes |
/** * Get the trusted keystore as configured in the extension properties. * * @return */ private KeyStore getTrustedKeyStore() { try { String keystorePassword = config.getProperty(RepositoryManagedSignatureProviderFactory.TRUSTED_KEYSTORE_PASSWORD); String keystorePath = config.getProperty(RepositoryManagedSignatureProviderFactory.TRUSTED_KEYSTORE_PATH); KeyStore keystore = KeyStore.getInstance("pkcs12"); FileInputStream keyStream = new FileInputStream(keystorePath); keystore.load(keyStream, keystorePassword.toCharArray()); // return the keystore return keystore; } catch(KeyStoreException kse) { throw new AlfrescoRuntimeException(kse.getMessage()); } catch (java.security.cert.CertificateException ce) { throw new AlfrescoRuntimeException(ce.getMessage()); } catch(NoSuchAlgorithmException nsaex) { throw new AlfrescoRuntimeException(nsaex.getMessage()); } catch (IOException ioex) { throw new AlfrescoRuntimeException(ioex.getMessage()); } }
Example 16
Source File: P12XdhMacContentSignerBuilder.java From xipki with Apache License 2.0 | 5 votes |
public ConcurrentContentSigner createSigner(int parallelism) throws XiSecurityException { Args.positive(parallelism, "parallelism"); List<XiContentSigner> signers = new ArrayList<>(parallelism); for (int i = 0; i < parallelism; i++) { XiContentSigner signer = new XdhMacContentSigner(hash, algId, key, peerIssuerAndSerial); signers.add(signer); } final boolean mac = true; DfltConcurrentContentSigner concurrentSigner; try { concurrentSigner = new DfltConcurrentContentSigner(mac, signers, key); } catch (NoSuchAlgorithmException ex) { throw new XiSecurityException(ex.getMessage(), ex); } concurrentSigner.setSha1DigestOfMacKey(HashAlgo.SHA1.hash(key.getEncoded())); if (certificateChain != null) { concurrentSigner.setCertificateChain(certificateChain); } else { concurrentSigner.setPublicKey(publicKey); } return concurrentSigner; }
Example 17
Source File: Mnemonic.java From jlibra with Apache License 2.0 | 5 votes |
public static Mnemonic fromByteSequence(ByteSequence byteSequence) { byte[] data = byteSequence.toArray(); if (data == null || data.length % 4 != 0) { throw new LibraRuntimeException("Data for mnemonic should have a length divisible by 4"); } MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new LibraRuntimeException(e.getMessage()); } byte[] check = digest.digest(data); boolean[] bits = new boolean[data.length * 8 + data.length / 4]; for (int i = 0; i < data.length; i++) { for (int j = 0; j < 8; j++) { bits[i * 8 + j] = ((data[i] & 0xff) & (1 << (7 - j))) > 0; } } for (int i = 0; i < data.length / 4; i++) { bits[8 * data.length + i] = ((check[i / 8] & 0xff) & (1 << (7 - (i % 8)))) > 0; } int mlen = data.length * 3 / 4; String[] memo = new String[mlen]; for (int i = 0; i < mlen; i++) { int index = 0; for (int j = 0; j < 11; j++) { if (bits[i * 11 + j]) { index += 1 << (10 - j); } } memo[i] = WORDS.get(index); } return new Mnemonic(memo); }
Example 18
Source File: DOMKeyValue.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
PublicKey unmarshalKeyValue(Element kvtElem) throws MarshalException { if (dsakf == null) { try { dsakf = KeyFactory.getInstance("DSA"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException ("unable to create DSA KeyFactory: " + e.getMessage()); } } Element curElem = DOMUtils.getFirstChildElement(kvtElem); // check for P and Q if (curElem.getLocalName().equals("P")) { p = new DOMCryptoBinary(curElem.getFirstChild()); curElem = DOMUtils.getNextSiblingElement(curElem, "Q"); q = new DOMCryptoBinary(curElem.getFirstChild()); curElem = DOMUtils.getNextSiblingElement(curElem); } if (curElem.getLocalName().equals("G")) { g = new DOMCryptoBinary(curElem.getFirstChild()); curElem = DOMUtils.getNextSiblingElement(curElem, "Y"); } y = new DOMCryptoBinary(curElem.getFirstChild()); curElem = DOMUtils.getNextSiblingElement(curElem); if (curElem != null && curElem.getLocalName().equals("J")) { j = new DOMCryptoBinary(curElem.getFirstChild()); // curElem = DOMUtils.getNextSiblingElement(curElem); } /* if (curElem != null) { seed = new DOMCryptoBinary(curElem.getFirstChild()); curElem = DOMUtils.getNextSiblingElement(curElem); pgen = new DOMCryptoBinary(curElem.getFirstChild()); } */ //@@@ do we care about j, pgenCounter or seed? DSAPublicKeySpec spec = new DSAPublicKeySpec(y.getBigNum(), p.getBigNum(), q.getBigNum(), g.getBigNum()); return generatePublicKey(dsakf, spec); }
Example 19
Source File: AbstractScramSHAMechanism.java From qpid-jms with Apache License 2.0 | 4 votes |
private byte[] calculateClientProof(final byte[] challenge) throws SaslException { try { String serverFirstMessage = new String(challenge, StandardCharsets.US_ASCII); String[] parts = serverFirstMessage.split(","); if (parts.length < 3) { throw new SaslException("Server challenge '" + serverFirstMessage + "' cannot be parsed"); } else if (parts[0].startsWith("m=")) { throw new SaslException("Server requires mandatory extension which is not supported: " + parts[0]); } else if (!parts[0].startsWith("r=")) { throw new SaslException("Server challenge '" + serverFirstMessage + "' cannot be parsed, cannot find nonce"); } String nonce = parts[0].substring(2); if (!nonce.startsWith(clientNonce)) { throw new SaslException("Server challenge did not use correct client nonce"); } serverNonce = nonce; if (!parts[1].startsWith("s=")) { throw new SaslException("Server challenge '" + serverFirstMessage + "' cannot be parsed, cannot find salt"); } String base64Salt = parts[1].substring(2); salt = Base64.getDecoder().decode(base64Salt); if (!parts[2].startsWith("i=")) { throw new SaslException("Server challenge '" + serverFirstMessage + "' cannot be parsed, cannot find iteration count"); } String iterCountString = parts[2].substring(2); iterationCount = Integer.parseInt(iterCountString); if (iterationCount <= 0) { throw new SaslException("Iteration count " + iterationCount + " is not a positive integer"); } byte[] passwordBytes = saslPrep(new String(getPassword())).getBytes(StandardCharsets.UTF_8); byte[] saltedPassword = generateSaltedPassword(passwordBytes); String clientFinalMessageWithoutProof = "c=" + Base64.getEncoder().encodeToString(GS2_HEADER.getBytes(StandardCharsets.US_ASCII)) + ",r=" + serverNonce; String authMessage = clientFirstMessageBare + "," + serverFirstMessage + "," + clientFinalMessageWithoutProof; byte[] clientKey = computeHmac(saltedPassword, "Client Key"); byte[] storedKey = MessageDigest.getInstance(digestName).digest(clientKey); byte[] clientSignature = computeHmac(storedKey, authMessage); byte[] clientProof = clientKey.clone(); for (int i = 0; i < clientProof.length; i++) { clientProof[i] ^= clientSignature[i]; } byte[] serverKey = computeHmac(saltedPassword, "Server Key"); serverSignature = computeHmac(serverKey, authMessage); String finalMessageWithProof = clientFinalMessageWithoutProof + ",p=" + Base64.getEncoder().encodeToString(clientProof); return finalMessageWithProof.getBytes(); } catch (NoSuchAlgorithmException e) { throw new SaslException(e.getMessage(), e); } }
Example 20
Source File: X509StreamParser.java From ripple-lib-java with ISC License | 3 votes |
/** * Generates a StreamParser object that implements the specified type. If * the default provider package provides an implementation of the requested * type, an instance of StreamParser containing that implementation is * returned. If the type is not available in the default package, other * packages are searched. * * @param type * The name of the requested X.509 object type. * @return a StreamParser object for the specified type. * * @exception NoSuchParserException * if the requested type is not available in the default * provider package or any of the other provider packages * that were searched. */ public static X509StreamParser getInstance(String type) throws NoSuchParserException { try { X509Util.Implementation impl = X509Util.getImplementation("X509StreamParser", type); return createParser(impl); } catch (NoSuchAlgorithmException e) { throw new NoSuchParserException(e.getMessage()); } }