Java为安全应用提供了丰富的API,J2SDK14 的JSSE (JavaTM Secure Socket Extension) 包括javaxsecuritycertificate包,并且提供对证书的 *** 作方法,代码如下:
import javaxswing;
import javaawt;
import javaawtevent;
import javaxswingtable;
import javasecuritycertCertificateFactory;
import javasecuritycertX509Certificate;
import javaio;
public class CARead extends JPanel {
private String CA_Name;
private String CA_ItemData[][] = new String[9][2];
private String[] columnNames = {"证书字段标记","内容" };
public CARead(String CertName) {
CA_Name=CertName;
/ 三个Panel用来显示证书内容/
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panelNormal = new JPanel();
tabbedPaneaddTab("普通信息", panelNormal);
JPanel panelAll=new JPanel();
panelAllsetLayout(new BorderLayout());
tabbedPaneaddTab("所有信息",panelAll);
JPanel panelBase64=new JPanel();
panelBase64setLayout(new BorderLayout());
tabbedPaneaddTab("Base64编码信息",panelBase64);
/ 读取证书常规信息 /
Read_Normal(panelNormal);
/ 读取证书文件字符串表示内容 /
Read_Bin(panelAll);
/ 读取证原始Base64编码形式的证书文件 /
Read_Raw(panelBase64);
tabbedPanesetSelectedIndex(0);
setLayout(new GridLayout(1, 1));
add(tabbedPane);
}
}
定义证书信息的读取函数如下:
private int Read_Normal(JPanel panel){
String Field;
try{
CertificateFactory certificate_factory=CertificateFactorygetInstance("X509");
FileInputStream file_inputstream=new FileInputStream(CA_Name);
X509Certificate
x509certificate=(X509Certificate)certificate_factorygenerateCertificate
(file_inputstream);
Field=x509certificategetType();
CA_ItemData[0][0]="类型";
CA_ItemData[0][1]=Field;
Field=IntegertoString(x509certificategetVersion());
CA_ItemData[1][0]="版本";
CA_ItemData[1][1]=Field;
Field=x509certificategetSubjectDN()getName();
CA_ItemData[2][0]="标题";
CA_ItemData[2][1]=Field;
/ 以下类似,这里省略
Field=x509certificategetNotBefore()toString();得到开始有效日期
Field=x509certificate getNotAfter()toString();得到截止日期
Field=x509certificategetSerialNumber()toString(16);得到序列号
Field=x509certificategetIssuerDN()getName();得到发行者名
Field=x509certificategetSigAlgName();得到签名算法
Field=x509certificategetPublicKey()getAlgorithm();得到公钥算法 /
file_inputstreamclose();
final JTable table = new JTable(CA_ItemData, columnNames);
TableColumn tc=null;
tc = tablegetColumnModel()getColumn(1);
tcsetPreferredWidth(600);
paneladd(table);
}catch(Exception exception){
exceptionprintStackTrace();
return -1;
}
return 0;
}
public static void main(String[] args) {
int[] jine = new int[5];
int sum = 0;
Scanner input = new Scanner(Systemin);
for (int a = 0; a < jinelength; a++) {
Systemoutprintln("请输入第" + (a + 1) + "次购买的金额:");
jine[a] = inputnextInt();
sum += jine[a];
}
Systemoutprintln("序号\t\t" + "金额(元)");
for (int a = 0; a < jinelength; a++) {
Systemoutprintln((a + 1) + "\t\t" + jine[a]);
}
Systemoutprintln("总金额(元):" + sum);
}
Oracle的话,用SEQUENCE,如果是JAVA的话,用一个变量来保存就好。
写个方法,下面只是演示,代码只是演示代码,实际根据自己情况自己补充:
public String getOrderNo(Date d) {
if (d == null) {
d = new Date();
}
String dOut = doFormat(d);// 自己写个处理函数处理日期到上面你说的格式。
Int lastNo = getLastNumberFromConfigFile(dOut);//自己写一个从配置文件里读取上面日期的函数,如果没有就返回0
lastNo ++;
setlastNumberToConfiFile(dOut, lastNo);
String sOut = dOut + (lastNo / 1000)subString(3, 3); //
return sOut;
}
如果是J2ee里是单线程 *** 作的话,可以这样,如果可能会多线程 *** 作,要加上synchronized或加LOCK来处理。
一、上Google搜一下Mac及CPU ID的C代码
二、上javasuncom找那个JNI的指南
三、你用二的方法把一的代码给包一下。
其实利用在java中的runtime来执行在win里面的ipconfig -all的命令可以实现的!!
javalangProcess proc = RuntimegetRuntime()exec("ipconfig /all");
InputStream istr = procgetInputStream();
byte[] data = new byte[1024];
istrread(data);
netdata = new String(data);
分析其中的netdata就是那!,有关cpu的可以类同实现!
通过JAVA来读取数字证书的方法获取20位指纹:
CAReadjava文件代码:
public class CARead extends JPanel {
private String CA_Name;
private String CA_ItemData[][] = new String[9][2];
private String[] columnNames = { "证书字段标记", "内容" };
public CARead(String CertName) {
CA_Name = CertName;
/ 三个Panel用来显示证书内容 /
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panelNormal = new JPanel();
tabbedPaneaddTab("普通信息", panelNormal);
JPanel panelAll = new JPanel();
panelAllsetLayout(new BorderLayout());
tabbedPaneaddTab("所有信息", panelAll);
JPanel panelBase64 = new JPanel();
panelBase64setLayout(new BorderLayout());
tabbedPaneaddTab("Base64编码形式的信息", panelBase64);
/ 读取证书常规信息 /
Read_Normal(panelNormal);
/ 读取证书文件字符串表示内容 /
Read_Bin(panelAll);
/ 以Base64编码形式读取证书文件的信息 /
Read_Raw(panelBase64);
tabbedPanesetSelectedIndex(0);
setLayout(new GridLayout(1, 1));
add(tabbedPane);
}
private int Read_Normal(JPanel panel) {
String Field;
try {
CertificateFactory certificate_factory = CertificateFactory
getInstance("X509");
FileInputStream file_inputstream = new FileInputStream(CA_Name);
X509Certificate x509certificate = (X509Certificate) certificate_factory
generateCertificate(file_inputstream);
Field = x509certificategetType();
CA_ItemData[0][0] = "类型";
CA_ItemData[0][1] = Field;
Field = IntegertoString(x509certificategetVersion());
CA_ItemData[1][0] = "版本";
CA_ItemData[1][1] = Field;
Field = x509certificategetSubjectDN()getName();
CA_ItemData[2][0] = "标题";
CA_ItemData[2][1] = Field;
Field=x509certificategetNotBefore()toString();//得到开始有效日期
CA_ItemData[3][0] = "开始有效日期";
CA_ItemData[3][1] = Field;
Field=x509certificate getNotAfter()toString();//得到截止日期
CA_ItemData[4][0] = "截止日期";
CA_ItemData[4][1] = Field;
Field=x509certificategetSerialNumber()toString(16);//得到序列号
CA_ItemData[5][0] = "序列号";
CA_ItemData[5][1] = Field;
Field=x509certificategetIssuerDN()getName();//得到发行者名
CA_ItemData[6][0] = "发行者名";
CA_ItemData[6][1] = Field;
Field=x509certificategetSigAlgName();//得到签名算法
CA_ItemData[7][0] = "签名算法";
CA_ItemData[7][1] = Field;
Field=x509certificategetPublicKey()getAlgorithm();//得到公钥算法
CA_ItemData[8][0] = "公钥算法";
CA_ItemData[8][1] = Field;
//关闭输入流对象
file_inputstreamclose();
final JTable table = new JTable(CA_ItemData, columnNames);
TableColumn tc = null; //表格列控制
tc = tablegetColumnModel()getColumn(1);//得到表头
tcsetPreferredWidth(600);//设置宽度
paneladd(table);//增加到布局面板
} catch (Exception exception) {
exceptionprintStackTrace(); //异常捕获、
return -1;
}
return 0;
}
//读取二进制指纹文件
private int Read_Bin(JPanel panel) {
try {
FileInputStream file_inputstream = new FileInputStream(CA_Name);
DataInputStream data_inputstream = new DataInputStream(
file_inputstream);
CertificateFactory certificatefactory = CertificateFactory
getInstance("X509");
byte[] bytes = new byte[data_inputstreamavailable()];
data_inputstreamreadFully(bytes);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
JEditorPane Cert_EditorPane;
Cert_EditorPane = new JEditorPane();
X509Certificate cert=null;
//遍历得到所有的证书属性
if (baisavailable() > 0)
{
cert = (X509Certificate) certificatefactory generateCertificate(bais);
Cert_EditorPanesetText(certtoString());
}
Cert_EditorPanedisable();
JScrollPane edit_scroll = new JScrollPane(Cert_EditorPane);
paneladd(edit_scroll);
file_inputstreamclose();
data_inputstreamclose();
} catch (Exception exception) {
exceptionprintStackTrace();
return -1;
}
return 0;
}
private int Read_Raw(JPanel panel) {
try {
JEditorPane Cert_EditorPane = new JEditorPane();
StringBuffer strBuffer =new StringBuffer();
File inputFile = new File(CA_Name);
FileReader in = new FileReader(inputFile);
char[] buf = new char[2000];
int len = inread(buf, 0, 2000);
for (int i = 1; i < len; i++) {
strBufferappend(buf[i]);
}
inclose();
Cert_EditorPanesetText(strBuffertoString());
Cert_EditorPanedisable();
JScrollPane edit_scroll = new JScrollPane(Cert_EditorPane);
paneladd(edit_scroll);
} catch (Exception exception) {
exceptionprintStackTrace();
return -1;
}
return 0;
}
}
以上就是关于如何用java程序实现加密的序列号全部的内容,包括:如何用java程序实现加密的序列号、java类中经常会出现一个常量是序列号,序列号是什么意思、java怎么去获取证书文件的信息等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)