java ´úÂëÉú³ÉÊý×ÖÖ¤Êé
http://liuleijsjx.javaeye.com/blog/422343
±¾È˸ÕдµÄѧϰÐĵà ϣÍûÄÜÓÐËù°ïÖú
/**
*´úÂëʵÀý ͨ¹ý·´±àÒë²é¿´keytoolµÄjava code»ñµÃµÄÊý×ÖÖ¤ÊéµÄÄÚ²¿Éú³É·½·¨
*ÍÆ¼öʹÓÃjdk1.5
**/
1¡£Ê×ÏÈÉú³Éselfcert
CertAndKeyGen cak = new CertAndKeyGen("RSA","MD5WithRSA",null);
//²ÎÊý·Ö±ðΪ ¹«Ô¿Ëã·¨ Ç©ÃûËã·¨ providername£¨ÒòΪ²»ÖªµÀÈ·ÇÐµÄ Ö»ºÃʹÓÃnull ¼ÈʹÓÃĬÈϵÄprovider£©
cak.generate(1024);
//Éú³ÉÒ»¶Ôkey ²ÎÊýΪkeyµÄ³¤¶È ¶ÔÓÚrsa²»ÄÜСÓÚ512
X500Name subject = new X500Name("CN=simic,o=shanghai");
//subject name
X509Certificate certificate = cak.getSelfCertificate(subject,10);
// ºóÒ»¸ölongÐͲÎÊý´ú±í´ÓÏÖÔÚ¿ªÊ¼µÄÓÐЧÆÚ µ¥Î»ÎªÃ루Èç¹û²»Ïë´ÓÏÖÔÚ¿ªÊ¼Ëã ¿ÉÒÔÔÚºóÃæ¸ÄÕâ¸öÓò£©
BASE64Encoder base64
= new BASE64Encoder();
FileOutputStream fos = new FileOutputStream(new File("d:\\test.crt"));
base64.encodeBuffer(certificate.getEncoded(), fos);
//Éú³ÉcertÎļþ base64¼ÓÃÜ µ±È»Ò²¿ÉÒÔ²»¼ÓÃÜ
2¡£Éú³É·Ç×ÔÇ©µÄcert
Ê×ÏȰ´ÕÕ1×ßÒ»±éÉú³ÉÒ»¸ö×Ôǩ֤Êé
byte certbytes[] = certificate.getEncoded();
X509CertImpl x509certimpl = new X509CertImpl(certbytes);
X509CertInfo x509certinfo = (X509CertInfo)x509certimpl.get("x509.info");
X500Name issuer = new X500Name("CN=fatal,o=shanghai");
x509certinfo.set("issuer.dname",issuer);
//ÉèÖÃissuerÓò
Date bdate = new Date();
Date edate = new Date();
edate.setTime(bdate.getTime() + validity * 1000L * 24L * 60L * 60L);
//validityΪÓÐЧʱ¼ä³¤¶È µ¥Î»ÎªÃë
CertificateValidity certificatevalidity = new CertificateValidity(bdate,
edate);
x509certinfo.set("validity", certificatevalidity);
//ÉèÖÃÓÐЧÆÚÓò£¨°üº¬¿ªÊ¼Ê±¼äºÍµ½ÆÚʱ¼ä£©ÓòÃûµÈͬÓëx509certinfo.VALIDITY
x509certinfo.set("serialNumber", new
CertificateSerialNumber((int)(date.getTime() / 1000L)));
//ÉèÖÃÐòÁкÅÓò
CertificateVersion cv = new CertificateVersion(CertificateVersion.V3);
x509certinfo.set(X509CertInfo.VERSION,cv);
//ÉèÖð汾ºÅ Ö»ÓÐv1 ,v2,v3Õ⼸¸öºÏ·¨Öµ
/**
*ÒÔÉÏÊÇÖ¤ÊéµÄ»ù±¾ÐÅÏ¢ Èç¹ûÒªÌí¼ÓÓû§À©Õ
Ïà¹ØÎĵµ£º
1.
˳Ðò¿ØÖÆ
if
else
switch
¿ÉÒÔÓÃbyte,short,char,int×öΪ±í´ïʽÀàÐÍ
Ñ»·½á¹¹
while
do ...while
for
±êÇ©Ìø×ª£º
outer:
break outer;
outer:
continue outer;
2.Êý×éÀàÐÍ
Êý×éÒ²ÊÇÒ»ÖÖÊý¾ÝÀàÐÍ£¬Ëü±¾ÉíÊÇÒýÓÃÀàÐÍ¡£
¾²Ì¬³õʼ»¯£º³ÌÐòÔ±ÏÔʾָ¶¨³õʼֵ£¬ÏµÍ³¾ö¶¨³¤¶È¡£
¶¯Ì¬ ......
package script;
import java.io.File;
import java.io.IOException;
public class Realname {
public static void main(String[] args) throws IOException
{
File oldFile = new File("d:/PMS");
if(!oldFile.exists())
{
oldFile. ......
1. byte Èç¹ûûÓи³Öµ£¬ÄÇôjava»á×Ô¶¯½«Ëü¸³ÖµÎª £¨byte£©0;
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
......
import java.io.*;
public class FileWrite {
public static void main(String args[]) {
String outPut = "C:\\bin";
StringBuffer ab = new StringBuffer();
for(int i=6;i<=30;i++){
ab.append("http://www.test.com/joke/index_"+i+".htm\r\n&qu ......