Exemple #1
0
  static MessageDigest createDigestInstance(String digestAlgOID, Provider provider)
      throws NoSuchAlgorithmException {
    String digestName = TSPUtil.getDigestAlgName(digestAlgOID);

    if (provider != null) {
      try {
        return MessageDigest.getInstance(digestName, provider);
      } catch (NoSuchAlgorithmException e) {
        // Ignore
      }
    }

    return MessageDigest.getInstance(digestName);
  }
Exemple #2
0
  static int getDigestLength(String digestAlgOID, String provider)
      throws NoSuchProviderException, TSPException {
    String digestName = TSPUtil.getDigestAlgName(digestAlgOID);

    try {
      Integer length = (Integer) digestLengths.get(digestAlgOID);

      if (length != null) {
        return length.intValue();
      }

      return MessageDigest.getInstance(digestName, provider).getDigestLength();
    } catch (NoSuchAlgorithmException e) {
      try {
        return MessageDigest.getInstance(digestName).getDigestLength();
      } catch (NoSuchAlgorithmException ex) {
        throw new TSPException("digest algorithm cannot be found.", ex);
      }
    }
  }