예제 #1
0
  MessageDigest createDigest(int algorithm) throws GeneralSecurityException, PGPException {
    MessageDigest dig;

    try {
      dig = helper.createDigest(PGPUtil.getDigestName(algorithm));
    } catch (NoSuchAlgorithmException e) {
      throw new PGPException("cannot find algorithm: " + e.getMessage(), e);
    } catch (NoSuchProviderException e) {
      throw new PGPException("cannot find provider: " + e.getMessage(), e);
    }

    return dig;
  }
예제 #2
0
  public Signature createSignature(int keyAlgorithm, int hashAlgorithm) throws PGPException {
    String encAlg;

    switch (keyAlgorithm) {
      case PublicKeyAlgorithmTags.RSA_GENERAL:
      case PublicKeyAlgorithmTags.RSA_SIGN:
        encAlg = "RSA";
        break;
      case PublicKeyAlgorithmTags.DSA:
        encAlg = "DSA";
        break;
      case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT: // in some malformed cases.
      case PublicKeyAlgorithmTags.ELGAMAL_GENERAL:
        encAlg = "ElGamal";
        break;
      case PublicKeyAlgorithmTags.ECDSA:
        encAlg = "ECDSA";
        break;
      default:
        throw new PGPException("unknown algorithm tag in signature:" + keyAlgorithm);
    }

    return createSignature(PGPUtil.getDigestName(hashAlgorithm) + "with" + encAlg);
  }