java安全性编程实例电子版书附源码,是网络安全编程者不可多得的好书

源代码在线查看: valisign.java

软件大小: 2426 K
上传用户: rentianchou
关键词: java 安全性 编程实例 电子版
下载地址: 免注册下载 普通下载 VIP

相关代码

				import java.io.*;
				import java.security.*;
				import java.security.cert.*;
				import java.security.cert.Certificate;
				import java.util.*;
				
				public class ValiSign{
				   public static void main(String args[ ]) throws Exception{
				
				          Certificate[] certpath=new Certificate[args.length-1];
				          CertificateFactory cf = CertificateFactory.getInstance("X.509");
				          int i;
				          for (i=0;i						  FileInputStream in=new FileInputStream(args[i]);
				                  certpath[i]=cf.generateCertificate(in);
				          }
				          // RootCert
				          FileInputStream in=new FileInputStream(args[i]);
				          Certificate trust=cf.generateCertificate(in);
				
					  boolean pass=false;	  
				          String reason="";
				          for(i=0;i				          	try{
				                     PublicKey pbk;
				                     if(i==certpath.length-1){
				                           pbk =trust.getPublicKey();
				                     }
				                     else{
				                           pbk = certpath[i+1].getPublicKey();
				                     }
				                     certpath[i].verify(pbk);
				                     pass=true;
				                }
				                catch (Exception e){ 
				                     pass=false;
				                     reason+=i+"  "+e.toString( );
						     break;
				                }
					  }
				
				          if(pass){
				                 System.out.println("signature verification OK");
					  }
					  else{
				                 System.out.println("signature verification failed in "+reason);
					  }
				   }  
				}			

相关资源