亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? fileencrypter.java.bak

?? 使用三重DES加密算法和替代加密算法對文件進(jìn)行加密的小程序
?? BAK
字號:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*; 
import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;

//================================================================================================================================
//構(gòu)造窗體,注冊事件監(jiān)聽,事件響應(yīng)
public class FileEncrypter extends JFrame
{
	public static final int WIDTH = 550;
	public static final int HEIGHT = 200;
	public static AbstractButton button;
	FileEncrypter()
	{
		setSize(WIDTH,HEIGHT);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		Toolkit tk = Toolkit.getDefaultToolkit();
		final Dimension screenSize = tk.getScreenSize();
		setLocation((screenSize.width - WIDTH)/2, (screenSize.height - HEIGHT)/2); 
		setTitle("文件加密器");
		final Container c = this.getContentPane();
		c.setLayout( new FlowLayout());
		JMenuBar bar = new JMenuBar();
		JMenu setting,help;
		setting = new JMenu ("設(shè)置(S)");
		help = new JMenu ("幫助(H)");
		JMenuItem about;
		about = new JMenuItem("關(guān)于...",KeyEvent.VK_A);
		about.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				JDialog d = new JDialog();
				d.setTitle("關(guān)于FileEncrypter");
				d.setLocation((screenSize.width - WIDTH + 200)/2, (screenSize.height - HEIGHT)/2);
				d.setSize(350,200);
				JPanel p=new JPanel();
				p.setLayout(new GridLayout(5,1));
				d.add(p);
				JLabel userName=new JLabel("           本機(jī)的用戶名為:"+System.getProperty("user.name"));
				JLabel osName=new JLabel("           本機(jī)的操作系統(tǒng)是:"+System.getProperty("os.name"));
				JLabel javaVersion=new JLabel("           本機(jī)中所安裝的Java SDK的版本號是:"+System.getProperty("java.version"));
				p.add(new JLabel("            FileEncrypter程序 "));
				p.add(osName);
				p.add(userName);
				p.add(javaVersion);
				p.add(new JLabel("            200610404141 馬宗驍"));
				getDefaultCloseOperation();
				d.setResizable(false);
				d.setVisible(true);
			}
		});
		JRadioButtonMenuItem specialRadio1 = new JRadioButtonMenuItem("替代加密算法");
		JRadioButtonMenuItem specialRadio2 = new JRadioButtonMenuItem("三重DES加密算法");
		class ItemHandler implements ItemListener
		{
			public void itemStateChanged(ItemEvent e)
			{
				button = (AbstractButton) e.getItem();
			}
		}
		specialRadio1.addItemListener(new ItemHandler());
		specialRadio2.addItemListener(new ItemHandler());
		ButtonGroup buttonGroup1 = new ButtonGroup();
		bar.add(setting);
		setting.setMnemonic(KeyEvent.VK_F);
		bar.add(help);
		help.setMnemonic(KeyEvent.VK_H);
		setting.add(specialRadio1);
		setting.add(specialRadio2);
		buttonGroup1.add(specialRadio1);
		buttonGroup1.add(specialRadio2);
		help.add(about);
		setJMenuBar (bar);		
		final FilePanel fp = new FilePanel("文件選擇");
		c.add(fp);
		final KeyPanel pp = new KeyPanel("    密碼     ");
		c.add(pp);
		JButton jbE = new JButton("加密");
		c.add(jbE);
		jbE.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				if(button == null)
				JOptionPane.showMessageDialog(null,"請選擇加密方式!","提示",JOptionPane.OK_OPTION);
				else
				{ 
				  File file = new File(fp.getFileName());
				  if (file.exists()&&button.getText().equals("三重DES加密算法"))
				  encrypt_des(file.getAbsoluteFile(),pp.getKey());
				  else if(file.exists()&&button.getText().equals("替代加密算法"))
				  encrypt_tidai(file.getAbsoluteFile(),pp.getKey());
				  else
				  JOptionPane.showMessageDialog(null,"請選擇文件!","提示",JOptionPane.OK_OPTION);
				}
			}
		});
		JButton jbD = new JButton("解密");
		c.add(jbD);
		jbD.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				if(button == null)
				JOptionPane.showMessageDialog(null,"請選擇加密方式!","提示",JOptionPane.OK_OPTION);
				else
				{
				  File file = new File(fp.getFileName());
			    if (file.exists()&&button.getText().equals("三重DES加密算法"))
			  	decrypt_des(file.getAbsoluteFile(),pp.getKey());
			  	else if(file.exists()&&button.getText().equals("替代加密算法"))
			  	decrypt_kaisa(file.getAbsoluteFile(),pp.getKey());
			    else
			    JOptionPane.showMessageDialog(null,"請選擇文件!","提示",JOptionPane.OK_OPTION);
			  }			  
			}
		});
		setVisible(true);
	}
//================================================================================================================================
//3DES算法	
  private void encrypt_des(File fileIn,String sKey)
	{
	  /*
	  在此添加加密函數(shù)
	  實(shí)現(xiàn)加密
	  */
	  try
	  { 
      if(sKey.length() == 48)
      { 
        byte[] bytK1 = getKeyByStr(sKey.substring(0,16)); 
        byte[] bytK2 = getKeyByStr(sKey.substring(16,32)); 
        byte[] bytK3 = getKeyByStr(sKey.substring(32,48)); 

        FileInputStream fis = new FileInputStream(fileIn); 
        byte[] bytIn = new byte[(int)fileIn.length()]; 
        for(int i = 0;i<fileIn.length();i++)
        { 
          bytIn[i] = (byte)fis.read(); 
        } 
        //加密 
        byte[] bytOut = encryptByDES(encryptByDES( 
        encryptByDES(bytIn,bytK1),bytK2),bytK3); 
        String fileOut = fileIn.getPath() + ".tdes"; 
        FileOutputStream fos = new FileOutputStream(fileOut); 
        for(int i = 0;i<bytOut.length;i++)
        { 
          fos.write((int)bytOut[i]); 
        } 
        fos.close(); 
        JOptionPane.showMessageDialog(this,"加密成功!","提示",JOptionPane.OK_OPTION); 
      }
      else 
      JOptionPane.showMessageDialog(this,"密碼長度必須等于48!","錯(cuò)誤信息",JOptionPane.ERROR_MESSAGE); 
    }
    catch(Exception e)
    { 
      e.printStackTrace(); 
    } 

	}
/*
在此添加解密函數(shù)
實(shí)現(xiàn)解密
*/
/** 
解密函數(shù) 
輸入: 
要解密的文件,密碼(由0-F組成,共48個(gè)字符,表示3個(gè)8位的密碼)如: 
AD67EA2F3BE6E5ADD368DFE03120B5DF92A8FD8FEC2F0746 
其中: 
AD67EA2F3BE6E5AD DES密碼一 
D368DFE03120B5DF DES密碼二 
92A8FD8FEC2F0746 DES密碼三 
輸出: 
對輸入的文件解密后,保存到用戶指定的文件中。 
*/ 
  private void decrypt_des(File fileIn,String sKey)
  { 
    try
    { 
      if(sKey.length() == 48)
      { 
        String strPath = fileIn.getPath(); 
        if(strPath.substring(strPath.length()-5).toLowerCase().equals(".tdes")) 
        strPath = strPath.substring(0,strPath.length()-5); 
        else
        { 
          JOptionPane.showMessageDialog(this,"不是合法的加密文件!","提示",JOptionPane.OK_OPTION); 
          return; 
        } 
        JFileChooser chooser = new JFileChooser(); 
        chooser.setCurrentDirectory(new File(".")); 
        chooser.setSelectedFile(new File(strPath)); 
        //用戶指定要保存的文件 
        int ret = chooser.showSaveDialog(this); 
        if(ret==JFileChooser.APPROVE_OPTION)
        { 
          byte[] bytK1 = getKeyByStr(sKey.substring(0,16)); 
          byte[] bytK2 = getKeyByStr(sKey.substring(16,32)); 
          byte[] bytK3 = getKeyByStr(sKey.substring(32,48)); 

          FileInputStream fis = new FileInputStream(fileIn); 
          byte[] bytIn = new byte[(int)fileIn.length()]; 
          for(int i = 0;i<fileIn.length();i++)
          { 
            bytIn[i] = (byte)fis.read(); 
          } 
          //解密 
          byte[] bytOut = decryptByDES(decryptByDES( 
          decryptByDES(bytIn,bytK3),bytK2),bytK1); 
          File fileOut = chooser.getSelectedFile(); 
          fileOut.createNewFile(); 
          FileOutputStream fos = new FileOutputStream(fileOut); 
          for(int i = 0;i<bytOut.length;i++)
          { 
            fos.write((int)bytOut[i]); 
          } 
          fos.close(); 
          JOptionPane.showMessageDialog(this,"解密成功!","提示",JOptionPane.OK_OPTION); 
        } 
      }
      else 
      JOptionPane.showMessageDialog(this,"密碼長度必須等于48!","錯(cuò)誤信息",JOptionPane.ERROR_MESSAGE); 
    }
    catch(Exception e)
    { 
      JOptionPane.showMessageDialog(this,"解密失敗,請核對密碼!","提示",JOptionPane.OK_OPTION); 
    } 
  } 

/** 
用DES方法加密輸入的字節(jié) 
bytKey需為8字節(jié)長,是加密的密碼 
*/ 
  private byte[] encryptByDES(byte[] bytP,byte[] bytKey) throws Exception
  { 
    DESKeySpec desKS = new DESKeySpec(bytKey); 
    SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); 
    SecretKey sk = skf.generateSecret(desKS); 
    Cipher cip = Cipher.getInstance("DES"); 
    cip.init(Cipher.ENCRYPT_MODE,sk); 
    return cip.doFinal(bytP); 
  } 

/** 
用DES方法解密輸入的字節(jié) 
bytKey需為8字節(jié)長,是解密的密碼 
*/ 
  private byte[] decryptByDES(byte[] bytE,byte[] bytKey) throws Exception
  { 
    DESKeySpec desKS = new DESKeySpec(bytKey); 
    SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); 
    SecretKey sk = skf.generateSecret(desKS); 
    Cipher cip = Cipher.getInstance("DES"); 
    cip.init(Cipher.DECRYPT_MODE,sk); 
    return cip.doFinal(bytE); 
  } 

/** 
輸入密碼的字符形式,返回字節(jié)數(shù)組形式。 
如輸入字符串:AD67EA2F3BE6E5AD 
返回字節(jié)數(shù)組:{173,103,234,47,59,230,229,173} 
*/ 
  private byte[] getKeyByStr(String str)
  { 
    byte[] bRet = new byte[str.length()/2]; 
    for(int i=0;i<str.length()/2;i++)
    { 
      Integer itg = new Integer(16*getChrInt(str.charAt(2*i)) + getChrInt(str.charAt(2*i+1))); 
      bRet[i] = itg.byteValue(); 
    } 
    return bRet; 
  } 
/** 
計(jì)算一個(gè)16進(jìn)制字符的10進(jìn)制值 
輸入:0-F 
*/ 
  private int getChrInt(char chr)
  { 
    int iRet=0; 
    if(chr=="0".charAt(0)) iRet = 0; 
    if(chr=="1".charAt(0)) iRet = 1; 
    if(chr=="2".charAt(0)) iRet = 2; 
    if(chr=="3".charAt(0)) iRet = 3; 
    if(chr=="4".charAt(0)) iRet = 4; 
    if(chr=="5".charAt(0)) iRet = 5; 
    if(chr=="6".charAt(0)) iRet = 6;
    if(chr=="7".charAt(0)) iRet = 7; 
    if(chr=="8".charAt(0)) iRet = 8; 
    if(chr=="9".charAt(0)) iRet = 9; 
    if(chr=="A".charAt(0)) iRet = 10;
    if(chr=="B".charAt(0)) iRet = 11; 
    if(chr=="C".charAt(0)) iRet = 12; 
    if(chr=="D".charAt(0)) iRet = 13; 
    if(chr=="E".charAt(0)) iRet = 14; 
    if(chr=="F".charAt(0)) iRet = 15; 
    return iRet; 
  }
//================================================================================================================================
//替代加密算法  
	private void encrypt_tidai(File fileIn,String sKey)
	{
		try
		{
			if(sKey.length() <= 2)
			{
			  int n = Integer.parseInt(sKey);
			  FileInputStream fis = new FileInputStream(fileIn);
			  byte[] bytIn = new byte[(int)fileIn.length()];
			  byte[] bytOut = new byte[(int)fileIn.length()];
			  for(int i = 0;i<fileIn.length();i++)
			  {
				  bytIn[i] = (byte)fis.read();
			  }
			  //jiami
			  for(int i = 0;i<fileIn.length();i++)
			  bytOut[i] = (byte)(bytIn[i]+n);
			  String fileOut = fileIn.getPath();// + ".tidai";
			  FileOutputStream fos = new FileOutputStream(fileOut);
			  for(int i = 0;i<bytOut.length;i++)
			  {
				  fos.write((int)bytOut[i]);
			  }
			  fos.close();
			  JOptionPane.showMessageDialog(this,"替代加密成功!","提示",JOptionPane.OK_OPTION);
		  }
		  else
		  JOptionPane.showMessageDialog(this,"密碼長度不正確!","錯(cuò)誤信息",JOptionPane.ERROR_MESSAGE);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	private void decrypt_kaisa(File fileIn,String sKey)
	{
		try
		{
			if(sKey.length() <= 2)
			{
				String strPath = fileIn.getPath();
				if(strPath.substring(strPath.length()-6).toLowerCase().equals(".tidai"))
				strPath = strPath.substring(0,strPath.length()-6);
				else
				{
					JOptionPane.showMessageDialog(this,"不是合法的加密文件!","提示",JOptionPane.OK_OPTION);
					return;
				}
				JFileChooser chooser = new JFileChooser();
				chooser.setCurrentDirectory(new File(""));
				chooser.setSelectedFile(new File(strPath));
				//用戶指定要保存的文件 
				int ret = chooser.showSaveDialog(this);
				if(ret==JFileChooser.APPROVE_OPTION)
				{
					int n = Integer.parseInt(sKey);
					FileInputStream fis = new FileInputStream(fileIn);
					byte[] bytIn = new byte[(int)fileIn.length()];
					byte[] bytOut = new byte[(int)fileIn.length()];
					for(int i = 0;i<fileIn.length();i++)
					{
						bytIn[i] = (byte)fis.read();
					}
					//解密
					for(int i = 0;i<fileIn.length();i++)
					bytOut[i] = (byte)(bytIn[i]-n);
					File fileOut = chooser.getSelectedFile();
					fileOut.createNewFile();
					FileOutputStream fos = new FileOutputStream(fileOut);
					for(int i = 0;i<bytOut.length;i++)
					{
						fos.write((int)bytOut[i]);
					}
					fos.close();
					JOptionPane.showMessageDialog(this,"解密成功!","提示",JOptionPane.OK_OPTION);
				}
			}
			else
			JOptionPane.showMessageDialog(this,"密碼長度必須小于等于2!","錯(cuò)誤信息",JOptionPane.ERROR_MESSAGE);
		}
		catch(Exception e)
		{
			JOptionPane.showMessageDialog(this,"解密失敗,請核對密碼!","提示",JOptionPane.OK_OPTION);
		}
	}
  private byte[] decryptByKS(byte[] bytE,byte[] bytKey)
  {
  	return bytE;
  }
//================================================================================================================================
//主函數(shù)
	public static void main(String args[])
	{
		FileEncrypter fe = new FileEncrypter();
	}
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品美女在线播放| 亚洲国产经典视频| bt7086福利一区国产| 91污在线观看| 精品一区二区三区蜜桃| 日韩毛片一二三区| 精品国产污网站| 欧美三片在线视频观看| 麻豆精品视频在线| 成人免费高清视频在线观看| 亚洲成人综合在线| 国产精品视频免费看| 91精品国产91久久久久久最新毛片| 成人免费视频网站在线观看| 蜜桃av一区二区| 亚洲电影中文字幕在线观看| 中文字幕欧美三区| 久久久精品2019中文字幕之3| 欧美吻胸吃奶大尺度电影| 成人av在线观| 国产成人亚洲综合a∨婷婷| 蜜桃精品视频在线观看| 亚洲第一福利一区| 亚洲精品国久久99热| 国产欧美日韩另类一区| 精品福利视频一区二区三区| 欧美一区二区三区视频在线观看| 一本久久综合亚洲鲁鲁五月天| 国产成人一区在线| 国产精品 日产精品 欧美精品| 美女一区二区久久| 日本不卡不码高清免费观看| 亚洲高清视频中文字幕| 久久人人爽爽爽人久久久| 波多野结衣精品在线| 国产精品自拍av| 美女视频一区二区三区| 蜜臀av一区二区三区| 麻豆成人久久精品二区三区小说| 亚洲高清不卡在线| 亚洲妇熟xx妇色黄| 五月婷婷激情综合网| 无码av中文一区二区三区桃花岛| 日韩影院免费视频| 免费在线成人网| 激情综合色播五月| 国产精品一区在线观看你懂的| 国产在线国偷精品免费看| 国产综合色精品一区二区三区| 精品一区二区三区在线观看国产| 狠狠狠色丁香婷婷综合激情| 国产精品影视网| 成人ar影院免费观看视频| av不卡一区二区三区| 欧美亚洲综合另类| 欧美一级黄色录像| 91国偷自产一区二区使用方法| 91高清视频免费看| 亚洲一区在线视频观看| 图片区小说区国产精品视频| 免费欧美日韩国产三级电影| 国产一区亚洲一区| 99视频热这里只有精品免费| 欧美网站一区二区| 欧美不卡一区二区三区四区| 国产日本欧美一区二区| 日韩毛片高清在线播放| 天天色天天爱天天射综合| 久草精品在线观看| 99精品国产视频| 51精品国自产在线| 国产欧美日韩在线| 亚洲一二三区视频在线观看| 极品少妇一区二区| 91免费视频观看| 日韩一区二区三区视频在线 | 91精品国产综合久久国产大片| 精品日韩一区二区三区| 亚洲色图.com| 免费观看日韩av| 99精品视频一区| 日韩无一区二区| 亚洲欧洲韩国日本视频| 麻豆一区二区三| 日本精品一级二级| 激情图片小说一区| 色999日韩国产欧美一区二区| 欧美电影免费观看高清完整版在线观看| 久久精品人人做人人综合| 亚洲综合区在线| 国产精品香蕉一区二区三区| 欧美日韩高清在线播放| 中文字幕一区av| 久草精品在线观看| 精品视频在线视频| 国产精品私人影院| 麻豆成人在线观看| 欧美视频你懂的| 国产精品美女久久久久高潮| 久久精品国产一区二区| 欧美午夜不卡视频| 国产精品久久久久久福利一牛影视 | 国产精品一二三区| 在线综合亚洲欧美在线视频| 日韩一区在线播放| 国产精华液一区二区三区| 日韩激情一区二区| 在线欧美一区二区| 中文一区二区在线观看| 久久精品国产精品亚洲精品 | 欧美日韩亚洲不卡| 国产精品不卡在线观看| 国产一区二区按摩在线观看| 欧美一卡二卡在线| 亚瑟在线精品视频| 91美女精品福利| 国产精品天美传媒| 国产精品乡下勾搭老头1| 欧美不卡视频一区| 日日欢夜夜爽一区| 欧美午夜片在线观看| 亚洲欧美成aⅴ人在线观看| 大胆亚洲人体视频| 欧美激情资源网| 国产精品99久| 国产亚洲短视频| 国产精品综合久久| 久久精品一区二区三区av| 精品一区二区三区在线观看国产| 日韩视频一区在线观看| 日韩av在线发布| 欧美久久久久久蜜桃| 亚洲成人高清在线| 欧美精品久久99| 日韩高清不卡一区二区| 91精品免费观看| 日韩精品福利网| 欧美一区二区三区成人| 久久精品国产一区二区| 欧美精品一区二区三区在线| 国产揄拍国内精品对白| 国产无人区一区二区三区| 国产经典欧美精品| 亚洲欧洲日韩综合一区二区| 色悠久久久久综合欧美99| 一区二区三区不卡在线观看| 一区二区不卡在线视频 午夜欧美不卡在 | 91麻豆文化传媒在线观看| 亚洲男女毛片无遮挡| 欧美在线看片a免费观看| 亚洲成人1区2区| 日韩欧美的一区| 国产伦精品一区二区三区免费迷| 国产嫩草影院久久久久| 99re热视频精品| 亚洲成a人片综合在线| 日韩免费观看2025年上映的电影| 国产呦萝稀缺另类资源| 18成人在线观看| 欧美日韩精品久久久| 精品中文字幕一区二区小辣椒| 久久久99精品久久| 一本久道久久综合中文字幕| 午夜精品一区二区三区电影天堂| 日韩一区二区在线播放| 懂色av一区二区三区免费看| 一区二区不卡在线播放| 精品日韩成人av| caoporen国产精品视频| 首页综合国产亚洲丝袜| 国产亚洲成aⅴ人片在线观看| 色94色欧美sute亚洲线路一久| 日本在线不卡一区| 中日韩av电影| 欧美精品国产精品| 国产成+人+日韩+欧美+亚洲| 亚洲国产va精品久久久不卡综合| 欧美精品一区二区三区在线| 色婷婷综合久久久中文一区二区| 美女网站在线免费欧美精品| 国产精品第四页| 日韩欧美一级特黄在线播放| 97久久人人超碰| 狠狠色丁香九九婷婷综合五月| 亚洲激情网站免费观看| 久久综合久久综合久久综合| 91福利社在线观看| 国产精品亚洲午夜一区二区三区 | 亚洲不卡av一区二区三区| 久久久精品黄色| 欧美乱妇一区二区三区不卡视频| 国产成人综合网| 日韩高清电影一区| 一区二区三区中文在线| 久久久综合九色合综国产精品| 欧美日韩亚洲高清一区二区| 99视频精品在线| 国产老肥熟一区二区三区| 日韩国产欧美在线播放| 亚洲女人的天堂|