?? test.java
字號:
package com.gmc.algorithms;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.Key;
import com.gmc.crypto.MessageDigester;
import com.gmc.crypto.SymmetryEncrypt;
/**
* 測試類
* @author wanna
*
*/
public class Test
{
public static void main(String[] args)
{
Test t = new Test();
//t.SHATest();
//t.DESTest();
t.RSATest();
}
public void SHATest()
{
MessageDigester md = new SHATools();
String str1 = "dsdfwerd";
String str2 = null;
byte []b= new byte[0];
File f = new File("E:\\55.txt");
try
{
System.out.println(md.encrypt(str1, null));
System.out.println(b.length);
System.out.println(md.encrypt(b, null));
System.out.println(md.encrypt(f, null));
FileInputStream fis = new FileInputStream(f);
System.out.println(md.encrypt(fis, null));
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void DESTest()
{
SymmetryEncrypt se = new DesedeTools();
try
{
//對字符串加解密成功
String str1 = "165464864";
String Mstr1 = se.encrypt(str1, null);
System.out.println(Mstr1);
Key k1= se.getKey();
System.out.println(se.decrypt(Mstr1.getBytes(), k1));
//對文件加解密成功
File f = new File("F:\\55.txt");
File f2 = se.encrypt(f, null);
Key k2 = se.getKey();
se.decrypt(f2, k2);
/*//對數據流加解密成功
InputStream is =new FileInputStream(new File("E:\\55.txt"));
File f3 = se.encrypt(is, null, "E:\\5.dfs");
Key k3 = se.getKey();
InputStream is2 = new FileInputStream(f3);
se.decrypt(is2, k3, "D:\\5.txt");*/
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void RSATest()
{
RSATools rt = new RSATools();
try
{
/*//對字符串加解密成功
String str1="sdfsfjpdiwdpdfipw";
System.out.println(str1);
String mstr1 = rt.encrypt(str1.getBytes(), null);
System.out.println(mstr1);
Key pubk1 = rt.getPublicKey();
Key prik1 = rt.getPrivateKey();
String jstr1 = rt.decrypt(mstr1.getBytes(), prik1);
System.out.println(jstr1);
String str2 = "3616516165";
System.out.println(str2);
String mstr2 = rt.encrypt(str2, pubk1);
System.out.println(mstr2);
System.out.println(rt.decrypt(mstr2.getBytes(), prik1));
*/
//對文件加解密成功
/*File f = new File("F:\\55.txt");
System.out.println(f.length());
File ef = rt.encrypt(f, null);
Key prik2= rt.getPrivateKey();
rt.decrypt(ef, prik2);
*/
//對數據流加解密成功
InputStream iss = new FileInputStream(new File("F:\\55.txt"));
File f5 = rt.encrypt(iss, null, "E:\\5.fjm");
InputStream iss2 = new FileInputStream(f5);
Key key = rt.getPrivateKey();
rt.decrypt(iss2,key ,"E:\\5555.txt");
/*對字符串簽名/驗證成功
String str3 ="146849sdfs錕斤拷";
System.out.println(str3);
String sstr3 =rt.digitalSignature(str3, null);
Key pubkey3 = rt.getPublicKey();
Key prikey3 = rt.getPrivateKey();
System.out.println(sstr3);
System.out.println(rt.validateSignature(str3, sstr3, pubkey3));*/
/*
// 對文件簽名/驗證成功
File f3 = new File("F:\\55.txt");
File sf3= rt.digitalSignature(f3, null);
Key pk3= rt.getPublicKey();
System.out.println(rt.validateSignature(f3, sf3, pk3));*/
//對數據流簽名/驗證成功
/*InputStream is = new FileInputStream(new File("E:\\55.txt"));
File f4 = rt.digitalSignature(is, null,null);
Key pk4 = rt.getPublicKey();
InputStream is2 = new FileInputStream(new File("E:\\55.txt"));
InputStream sign = new FileInputStream(f4);
System.out.println(rt.validateSignature(is2,sign,pk4));
*/
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -