コード例 #1
0
  public static void main(String[] args) throws Exception {

    Provider p = new com.sun.exp.provider.EXP();
    Security.insertProviderAt(p, 1);

    Object[] signers = p.getClass().getSigners();
    if (signers == null || signers.length <= 0) {
      throw new SecurityException("Test Failed");
    } else {
      for (int i = 0; i < signers.length; i++) {
        System.out.println("signer [" + i + "] = " + signers[i]);
      }
    }

    MessageDigest md = MessageDigest.getInstance("SHA1");
    System.out.println("test passed");
  }
コード例 #2
0
 /**
  * Calculates the hash of the certificate known as the "thumbprint" and returns it as a string
  * representation.
  *
  * @param cert The certificate to hash.
  * @param algorithm The hash algorithm to use.
  * @return The SHA-1 hash of the certificate.
  * @throws CertificateException
  */
 private static String getThumbprint(X509Certificate cert, String algorithm)
     throws CertificateException {
   MessageDigest digest;
   try {
     digest = MessageDigest.getInstance(algorithm);
   } catch (NoSuchAlgorithmException e) {
     throw new CertificateException(e);
   }
   byte[] encodedCert = cert.getEncoded();
   StringBuilder sb = new StringBuilder(encodedCert.length * 2);
   Formatter f = new Formatter(sb);
   try {
     for (byte b : digest.digest(encodedCert)) f.format("%02x", b);
   } finally {
     f.close();
   }
   return sb.toString();
 }