java.security.NoSuchAlgorithmException#getMessage ( )源码实例Demo

下面列出了java.security.NoSuchAlgorithmException#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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()});
   }
}
 
源代码2 项目: wetech-cms   文件: UserService.java
@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;
}
 
源代码3 项目: presto   文件: AesSpillCipher.java
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);
    }
}
 
源代码4 项目: jlibra   文件: Mnemonic.java
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);
}
 
源代码5 项目: xipki   文件: P12XdhMacContentSignerBuilder.java
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;
}
 
/**
 * 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());
	} 
}
 
源代码7 项目: wetech-cms   文件: UserService.java
@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());
	}
}
 
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()});
   }
}
 
源代码9 项目: oodt   文件: MD5GetHandler.java
public MD5GetHandler() throws InstantiationException {
  try {
    this.md = MessageDigest.getInstance("MD5");
  } catch (NoSuchAlgorithmException e) {
    LOG.log(Level.SEVERE, e.getMessage());
    throw new InstantiationException(e.getMessage());
  }
}
 
源代码10 项目: xipki   文件: XijsonCertprofile.java
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());
      }
    }
  }
}
 
源代码11 项目: RipplePower   文件: X509Store.java
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());
    }
}
 
源代码12 项目: jdk8u-jdk   文件: Util.java
/**
 * 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;
}
 
源代码13 项目: j2objc   文件: NoSuchAlgorithmExceptionTest.java
/**
 * 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);
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: Util.java
/**
 * 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;
}
 
源代码15 项目: jdk8u60   文件: Util.java
/**
 * 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;
}
 
源代码16 项目: onetwo   文件: AESEncryptCoder.java
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;
	}
 
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()});
   }
}
 
源代码18 项目: qpid-jms   文件: AbstractScramSHAMechanism.java
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);
    }
}
 
源代码19 项目: jdk8u-jdk   文件: DOMKeyValue.java
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);
}
 
源代码20 项目: ripple-lib-java   文件: X509StreamParser.java
/**
 * 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());
    }
}