Java Tutorial/Security/Principal — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 05:01, 1 июня 2010

Principal and Certificate

import java.io.FileInputStream;
import java.security.Principal;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
public class MainClass {
  public static void main(String args[]) throws Exception {
    Certificate[] certpath = new Certificate[args.length];
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    for (int i = 0; i < args.length; i++) {
      FileInputStream in = new FileInputStream(args[i]);
      certpath[i] = cf.generateCertificate(in);
    }
    for (int i = 0; i < certpath.length - 1; i++) {
      Principal issuer = ((X509Certificate) certpath[i]).getIssuerDN();
      Principal subject = ((X509Certificate) certpath[i + 1]).getSubjectDN();
      if (!issuer.equals(subject)) {
        System.out.println("in " + i + " issuer is " + issuer);
        System.out.println("But in " + (i + 1));
        System.out.println("subject is " + subject);
        break;
      }
    }
  }
}