⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 security_kind.java

📁 这是我收集的毕业师兄的毕业设计,具体的功能我也不清楚,不过是可以用来答辩的,完整的毕业设计,有源代码,可爱执行文件,文档资料.
💻 JAVA
字号:
package security;
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
import java.security.*;
import java.security.interfaces.*;
import java.security.spec.*;
import java.math.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import java.lang.*;
public class  security_kind
{public static void main(String args[]) throws Exception
	{}
public  String RSA(String s)throws Exception
	{	String returnstr=new String("");
		FileInputStream Lfile=new FileInputStream("Skey_RSA_pub.dat");
	      ObjectInputStream ob=new ObjectInputStream(Lfile);
          RSAPublicKey pbk=(RSAPublicKey)ob.readObject();
		  BigInteger ee=pbk.getPublicExponent();
          BigInteger n=pbk.getModulus();
		  byte ptext[]=s.getBytes("UTF8");//字符串变成字数组
		  BigInteger m=new BigInteger(ptext);
		  BigInteger c=m.modPow(ee,n);
		returnstr=c.toString();
		 return returnstr;
	}
  public String simpleness(int a,String s) //简单加密,输入加密位数及字符串,输出字符串
	{String returnstr=new String("");
	for(int i=0;i<s.length();i++)
		{char c=s.charAt(i);
			c+=a;
			returnstr+=c;
		}
		return returnstr;
	}
  public String symmetry(String s)throws Exception//DESede对称密码,密钥为key1.dat,针对数组的加密。输入字符串,密文输出为字符串,可用中文
	{ 
	 FileInputStream f=new FileInputStream("key1.dat");
     ObjectInputStream b=new ObjectInputStream(f);
	 Key k=(Key)b.readObject();
	 Cipher cp=Cipher.getInstance("DESede");
	 cp.init(Cipher.ENCRYPT_MODE,k);
     byte ptext[]=s.getBytes("UTF8");
	 byte  ctext[]=cp.doFinal(ptext);
     FileOutputStream f2=new FileOutputStream("DES.dat");
	 f2.write(ctext);
	 String returnstr=new String(ctext,"UTF8");//字符数组为字符串
	 return returnstr;
	}
   public void Messagebrief(String str) throws Exception
	{MessageDigest m=MessageDigest.getInstance("MD5");
         FileInputStream fin=new FileInputStream(str+".txt");
         DigestInputStream din=new DigestInputStream(fin,m);
         while(din.read()!=-1);
         byte[] s=m.digest();
         String result="";
         for(int i=0;i<s.length;i++)
             {result+=Integer.toHexString((0x000000ff&s[i])|0xffffff00).substring(6);}
         FileWriter finout=new FileWriter(str+".brief");
         finout.write(result,0,result.length());
         finout.flush();
         }
public int unMessagebrief(String str) throws Exception
	{File comfile=new File(str);
         boolean is_exit=comfile.exists() ;
         if(is_exit)
         {MessageDigest m=MessageDigest.getInstance("MD5");
         int tempnumber=str.indexOf(".");
         String tempstr=new String(str.substring(0,tempnumber));
         FileInputStream fin=new FileInputStream(str);
         DigestInputStream din=new DigestInputStream(fin,m);
         while(din.read()!=-1);
         byte[] s=m.digest();
         String result="";
         for(int i=0;i<s.length;i++)
             {result+=Integer.toHexString((0x000000ff&s[i])|0xffffff00).substring(6);}
         FileReader finin=new FileReader(tempstr+".brief");BufferedReader in=new BufferedReader(finin);
         String result2=in.readLine();
         if(result2.equals(result))
             return 1;
         else return 0;
           }
         else return 1;
         }
   public String CBC(String s)throws Exception//CBC方式加密,密钥为key1.dat,
	  {
		FileInputStream f1=new FileInputStream("key1.dat");
        ObjectInputStream b1=new ObjectInputStream(f1);
	    Key k=(Key)b1.readObject();
	    byte[] rand=new byte[8];
		Random r=new Random();
		r.nextBytes(rand);
		IvParameterSpec iv=new IvParameterSpec(rand);
		Cipher cp=Cipher.getInstance("DESede/CBC/PKCS5Padding");
		cp.init(Cipher.ENCRYPT_MODE,k,iv);
		byte ptext[]=s.getBytes("UTF8");
		byte ctext[]=cp.doFinal(ptext);
        FileOutputStream f2=new FileOutputStream("CBC.dat");
		f2.write(rand);
		f2.write(ctext);
		byte[]tt=new byte[100];
		for(int i=0;i<rand.length;i++)
			tt[i]=rand[i];
		String returnstr=new String(ctext,"UTF8");
		System.out.println(returnstr);
		return returnstr;
	  }
public int file_symmetry(String s)throws Exception//文件DESede对称密码,密钥为key1.dat,针对数组的加密。输入字符串,密文输出为字符串,可用中文
	{File f_del=new File(s);
         int a=s.indexOf(".");
         String f_name=new String(s.substring(0,a));
         FileInputStream f=new FileInputStream("key1.dat");
         ObjectInputStream b=new ObjectInputStream(f);
	 Key k=(Key)b.readObject();
	 Cipher cp=Cipher.getInstance("DESede");
	 cp.init(Cipher.ENCRYPT_MODE,k);
         FileInputStream in_file=new FileInputStream(s);
         FileOutputStream out_file=new FileOutputStream(f_name+".symmetry");
         CipherOutputStream cout=new CipherOutputStream(out_file,cp);
         int is_read=0;
         while((is_read=in_file.read())!=-1)
             {cout.write(is_read);}
         cout.close();out_file.close();in_file.close();f_del.delete();
         return 1;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -