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

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

?? encipherdecipher.java

?? java的一些教程 大家看看,很有用的
?? JAVA
字號(hào):
// EncipherDecipher.java
// Displays a frame that allows users to specify
// a password and a file name. Contents written
// to an Editor Pane can be encrypted and written
// to a file, or encrypted contents can be read from
// a file and decrypted
package com.deitel.advjhtp1.security.jce;

// Java core package
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.security.*;
import java.security.spec.*;

// third-party packages
import com.sun.crypto.provider.SunJCE;

// Java extension package
import javax.swing.*;
import javax.crypto.*;
import javax.crypto.spec.*;

public class EncipherDecipher extends JFrame {

   // salt for password-based encryption-decryption algorithm
   private static final byte[] salt = {
      ( byte )0xf5, ( byte )0x33, ( byte )0x01, ( byte )0x2a,
      ( byte )0xb2, ( byte )0xcc, ( byte )0xe4, ( byte )0x7f
   };
    
   // iteration count
   private int iterationCount = 100;

   // user input components.
   private JTextField passwordTextField;
   private JTextField fileNameTextField;
   private JEditorPane fileContentsEditorPane;
    
   // frame constructor
   public EncipherDecipher() {

      // set security provider
      Security.addProvider( new SunJCE() );

      // initialize main frame
      setSize( new Dimension( 400, 400 ) );
      setTitle( "Encryption and Decryption Example" );
      
      // construct top panel
      JPanel topPanel = new JPanel();     
      topPanel.setBorder( BorderFactory.createLineBorder( 
         Color.black ) );
      topPanel.setLayout( new BorderLayout() );      

      // panel where password and file name labels will be placed
      JPanel labelsPanel = new JPanel();
      labelsPanel.setLayout( new GridLayout( 2, 1 ) );
      JLabel passwordLabel = new JLabel( " Password: " );
      JLabel fileNameLabel = new JLabel( " File Name: " );
      labelsPanel.add( fileNameLabel );
      labelsPanel.add( passwordLabel );
      topPanel.add( labelsPanel, BorderLayout.WEST );

      // panel where password and file name textfields will be placed
      JPanel textFieldsPanel = new JPanel();
      textFieldsPanel.setLayout( new GridLayout( 2, 1 ) );
      passwordTextField = new JPasswordField();
      fileNameTextField = new JTextField();
      textFieldsPanel.add( fileNameTextField );
      textFieldsPanel.add( passwordTextField );
      topPanel.add( textFieldsPanel, BorderLayout.CENTER );
     
      // construct middle panel
      JPanel middlePanel = new JPanel();
      middlePanel.setLayout( new BorderLayout() );

      // construct and place title label for contents pane
      JLabel fileContentsLabel = new JLabel();
      fileContentsLabel.setText( " File Contents" );
      middlePanel.add( fileContentsLabel, BorderLayout.NORTH );
      
      // initialize and place editor pane within scroll panel
      fileContentsEditorPane = new JEditorPane();
      middlePanel.add(  
         new JScrollPane( fileContentsEditorPane ),
                          BorderLayout.CENTER );
      
      // construct bottom panel
      JPanel bottomPanel = new JPanel();
      
      // create encrypt button
      JButton encryptButton = 
         new JButton( "Encrypt and Write to File" );
      encryptButton.addActionListener( 
      
         new ActionListener() {
            
            public void actionPerformed( ActionEvent event ) 
            {
               encryptAndWriteToFile();
            }
         }
      );
      bottomPanel.add( encryptButton );

      // create decrypt button
      JButton decryptButton = 
         new JButton( "Read from File and Decrypt" );
      decryptButton.addActionListener( 
      
         new ActionListener() {
      
            public void actionPerformed( ActionEvent event ) 
            {
               readFromFileAndDecrypt();
            }
         }
      );
      bottomPanel.add( decryptButton );

      // initialize main frame window
      JPanel contentPane = ( JPanel ) this.getContentPane();
      contentPane.setLayout( new BorderLayout() );
      contentPane.add( topPanel, BorderLayout.NORTH );
      contentPane.add( middlePanel, BorderLayout.CENTER );
      contentPane.add( bottomPanel, BorderLayout.SOUTH );
      
   } // end constructor
   
   // obtain contents from editor pane and encrypt
   private void encryptAndWriteToFile() 
   {
   
      // obtain user input
      String originalText = fileContentsEditorPane.getText();
      String password = passwordTextField.getText();
      String fileName = fileNameTextField.getText();

      // create secret key and get cipher instance
      Cipher cipher = null;
      
      try {
          
         // create password based encryption key object
         PBEKeySpec keySpec = 
            new PBEKeySpec( password.toCharArray() );
                  
         // obtain instance for secret key factory
         SecretKeyFactory keyFactory = 
            SecretKeyFactory.getInstance( "PBEWithMD5AndDES" );
         
         // generate secret key for encryption
         SecretKey secretKey = keyFactory.generateSecret( keySpec );

         // specifies parameters used with password based encryption
         PBEParameterSpec parameterSpec = 
            new PBEParameterSpec( salt, iterationCount );
         
         // obtain cipher instance reference
         cipher = Cipher.getInstance( "PBEWithMD5AndDES" );
   
         // initialize cipher in encrypt mode
         cipher.init( Cipher.ENCRYPT_MODE, secretKey, 
            parameterSpec );
      } 
      
      // handle NoSuchAlgorithmException 
      catch ( NoSuchAlgorithmException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }
      
      // handle InvalidKeySpecException 
      catch ( InvalidKeySpecException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }
      
      // handle InvalidKeyException 
      catch ( InvalidKeyException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }
      
      // handle NoSuchPaddingException 
      catch ( NoSuchPaddingException exception ) {
         exception.printStackTrace();
         System.exit( 1 );          
      }
      
      // handle InvalidAlgorithmParameterException 
      catch ( InvalidAlgorithmParameterException exception ) {
         exception.printStackTrace();
         System.exit( 1 );          
      }
     
      // create array of bytes
      byte[] outputArray = null;

      try {
         outputArray = originalText.getBytes( "ISO-8859-1" );
      } 
      
      // handle UnsupportedEncodingException
      catch ( UnsupportedEncodingException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }
      
      // create FileOutputStream
      File file = new File( fileName );
      FileOutputStream fileOutputStream = null;
      
      try {
         fileOutputStream = new FileOutputStream( file );
      } 
      
      // handle IOException
      catch ( IOException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }
      
      // create CipherOutputStream
      CipherOutputStream out = 
         new CipherOutputStream( fileOutputStream, cipher );
      
      // write contents to file and close
      try {
         out.write( outputArray );
         out.flush();
         out.close();
      } 
      
      // handle IOException 
      catch ( IOException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }
         
      // contain bytes read from file
      Vector fileBytes = new Vector();

      // read contents from file to show user encrypted text
      try {
         FileInputStream in = new FileInputStream( file );
            
         // read bytes from stream.
         byte contents;
         
         while ( in.available() > 0 ) {
            contents = ( byte )in.read();
            fileBytes.add( new Byte( contents ) );
         }
           
         in.close();
      } 
      
      // handle IOException
      catch ( IOException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }
      
      // create byte array from contents in Vector fileBytes
      byte[] encryptedText = new byte[ fileBytes.size() ];
      
      for ( int i = 0; i < fileBytes.size(); i++ ) {
         encryptedText[ i ] = 
            ( ( Byte ) fileBytes.elementAt( i ) ).byteValue();
      }
      
      // update Editor Pane contents
      fileContentsEditorPane.setText( new String( encryptedText ) );      
   }

   // obtain contents from file and decrypt
   private void readFromFileAndDecrypt() 
   {

      // used to rebuild byte list
      Vector fileBytes = new Vector();
          
      // obtain user input
      String password = passwordTextField.getText();
      String fileName = fileNameTextField.getText();

      // create secret key
      Cipher cipher = null;
      
      try {
         // create password based encryption key object
         PBEKeySpec keySpec = 
            new PBEKeySpec( password.toCharArray() );
                  
         // obtain instance for secret key factory
         SecretKeyFactory keyFactory = 
            SecretKeyFactory.getInstance( "PBEWithMD5AndDES" );
         
         // generate secret key for encryption
         SecretKey secretKey = keyFactory.generateSecret( keySpec );

         // specifies parameters used with password based encryption
         PBEParameterSpec parameterSpec = 
            new PBEParameterSpec( salt, iterationCount );         
         
         // obtain cipher instance reference.
         cipher = Cipher.getInstance( "PBEWithMD5AndDES" );
   
         // initialize cipher in decrypt mode
         cipher.init( Cipher.DECRYPT_MODE, secretKey, 
            parameterSpec );
      }
      
      // handle NoSuchAlgorithmException 
      catch ( NoSuchAlgorithmException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }
      
      // handle InvalidKeySpecException 
      catch ( InvalidKeySpecException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }
      
      // handle InvalidKeyException 
      catch ( InvalidKeyException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }

      // handle NoSuchPaddingException 
      catch ( NoSuchPaddingException exception ) {
         exception.printStackTrace();
         System.exit( 1 );          
      }
      
      // handle InvalidAlgorithmParameterException 
      catch ( InvalidAlgorithmParameterException exception ) {
         exception.printStackTrace();
         System.exit( 1 );          
      }

         
      // read and decrypt contents from file
      try {
         File file = new File( fileName );
         FileInputStream fileInputStream = 
            new FileInputStream( file );
         
         CipherInputStream in = 
            new CipherInputStream( fileInputStream, cipher );
         
         // read bytes from stream.
         byte contents = ( byte ) in.read();
         
         while ( contents != -1 ) {   
            fileBytes.add( new Byte( contents ) );
            contents = ( byte ) in.read();
         }           
         in.close();
      
      } 
      
      // handle IOException
      catch ( IOException exception ) {
         exception.printStackTrace();
         System.exit( 1 );
      }
      
      // create byte array from contents in Vector fileBytes
      byte[] decryptedText = new byte[ fileBytes.size() ];
      
      for ( int i = 0; i < fileBytes.size(); i++ ) {
         decryptedText[ i ] = 
            ( ( Byte )fileBytes.elementAt( i ) ).byteValue();
      }
                
      // update Editor Pane contents.
      fileContentsEditorPane.setText( new String( decryptedText ) );
   }
   
   // create frame and display
   public static void main( String[] args ) 
   {
      EncipherDecipher crypto = 
         new EncipherDecipher();
      crypto.validate();
      crypto.setVisible( true );       
   }
}

/***************************************************************
 * (C) Copyright 2002 by Deitel & Associates, Inc. and         *
 * Prentice Hall. All Rights Reserved.                         *
 *                                                             *
 * DISCLAIMER: The authors and publisher of this book have     *
 * used their best efforts in preparing the book. These        *
 * efforts include the development, research, and testing of   *
 * the theories and programs to determine their effectiveness. *
 * The authors and publisher make no warranty of any kind,     *
 * expressed or implied, with regard to these programs or to   *
 * the documentation contained in these books. The authors     *
 * and publisher shall not be liable in any event for          *
 * incidental or consequential damages in connection with, or  *
 * arising out of, the furnishing, performance, or use of      *
 * these programs.                                             *
 ***************************************************************/

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91国偷自产一区二区开放时间| 国产福利一区在线观看| 国产毛片精品视频| 欧美一区午夜视频在线观看| 亚洲精品视频在线观看网站| 国产经典欧美精品| 丝袜美腿亚洲色图| 在线播放/欧美激情| 日本特黄久久久高潮| 欧美一区二区视频在线观看| eeuss鲁片一区二区三区| 久久精品日产第一区二区三区高清版| 免费成人在线视频观看| 日韩欧美电影一二三| 青青草国产成人av片免费| 一区视频在线播放| 色婷婷综合久久| 亚洲国产美女搞黄色| 欧美乱妇一区二区三区不卡视频 | 精品国产一区二区国模嫣然| 日本91福利区| 亚洲激情自拍偷拍| 国产精品的网站| 在线免费观看不卡av| 日日骚欧美日韩| 亚洲精品国产精华液| 综合在线观看色| 欧美乱妇15p| 欧美视频三区在线播放| 久久99精品国产| 欧美激情中文字幕| 在线精品视频免费观看| 成人91在线观看| 午夜精品福利一区二区蜜股av| 精品福利一区二区三区免费视频| 欧美日韩一区视频| 国产精品 日产精品 欧美精品| 免费的国产精品| 免费看日韩a级影片| 青青草原综合久久大伊人精品| 日欧美一区二区| 日韩精品亚洲一区| 蜜臀国产一区二区三区在线播放| 国产精品久久久久婷婷| 国产精品乱码妇女bbbb| 91精品黄色片免费大全| 欧美日本一区二区在线观看| 成人美女视频在线观看18| 丝袜脚交一区二区| 日本成人在线不卡视频| 美洲天堂一区二卡三卡四卡视频| 奇米精品一区二区三区在线观看| 青青草国产成人99久久| 经典三级一区二区| 国产精品99久久久久久似苏梦涵 | 3d成人h动漫网站入口| 欧美精品自拍偷拍动漫精品| 日韩丝袜美女视频| 欧美在线制服丝袜| 欧美区在线观看| 精品国产乱码久久久久久图片 | 欧美顶级少妇做爰| 欧美日韩1234| 欧美v日韩v国产v| 7777精品伊人久久久大香线蕉 | 看片的网站亚洲| 五月综合激情日本mⅴ| 蜜臀精品一区二区三区在线观看 | 中文字幕视频一区二区三区久| 1区2区3区欧美| 亚洲成av人综合在线观看| 亚洲少妇30p| 亚洲成人福利片| 九九国产精品视频| 成人av午夜影院| 欧美在线一二三| 久久综合久久综合久久综合| 日韩一区二区三区av| 久久久激情视频| 国产亚洲欧洲一区高清在线观看| 亚洲视频资源在线| 另类的小说在线视频另类成人小视频在线| 国产一区91精品张津瑜| 色成人在线视频| 精品电影一区二区| 亚洲另类色综合网站| 久久国产剧场电影| 在线欧美一区二区| 久久夜色精品国产欧美乱极品| 亚洲另类一区二区| 国产一区二区三区不卡在线观看| 色呦呦网站一区| 久久奇米777| 午夜精品福利在线| av一区二区不卡| 欧美成人一区二区三区片免费| 亚洲图片你懂的| 国产一区二区三区在线看麻豆| 欧美亚洲另类激情小说| 国产精品欧美一级免费| 老司机精品视频在线| 欧美色手机在线观看| 中文字幕av一区二区三区高 | 99久久婷婷国产| 色网综合在线观看| 26uuu久久天堂性欧美| 亚洲福利国产精品| 91在线云播放| 久久精品网站免费观看| 蜜桃av一区二区在线观看| 欧洲亚洲精品在线| 国产精品久久福利| 国产精品影音先锋| 精品美女一区二区| 日韩中文字幕麻豆| 欧美午夜精品一区二区蜜桃 | 午夜精品久久久久久久久久久 | 91福利社在线观看| 国产精品欧美一区二区三区| 国产一区二三区好的| 日韩一级在线观看| 石原莉奈在线亚洲二区| 欧美视频中文一区二区三区在线观看 | 国产自产视频一区二区三区| bt欧美亚洲午夜电影天堂| 精品国产1区二区| 久久av资源站| 日韩欧美国产精品| 日本不卡一二三| 91精品国产色综合久久不卡电影| 亚洲电影视频在线| 在线免费观看日本欧美| 一区二区三区鲁丝不卡| 久久er99精品| 欧美v亚洲v综合ⅴ国产v| 开心九九激情九九欧美日韩精美视频电影| 欧美日韩一区二区三区在线 | 中文字幕中文字幕一区二区| 国产成人av一区| 国产欧美精品日韩区二区麻豆天美| 亚洲美女一区二区三区| 喷水一区二区三区| 日韩亚洲电影在线| 精品写真视频在线观看 | 亚洲自拍偷拍av| 国产jizzjizz一区二区| 在线成人高清不卡| 琪琪一区二区三区| 欧美成人高清电影在线| 久久国产夜色精品鲁鲁99| ww亚洲ww在线观看国产| 国产高清精品在线| 中文字幕日本不卡| 91国偷自产一区二区三区观看| 午夜一区二区三区视频| 欧美日韩一区二区电影| 日本va欧美va瓶| 国产日韩欧美电影| 91一区二区在线| 国产欧美一区二区在线观看| 成人国产免费视频| 亚洲乱码日产精品bd| 7777精品伊人久久久大香线蕉经典版下载 | 日韩国产高清在线| 久久久久综合网| 91一区二区三区在线播放| 亚洲成人av电影在线| 91精品福利在线一区二区三区| 国产乱子轮精品视频| 1024成人网| 91精品国产高清一区二区三区| 国产综合色在线| 亚洲美女少妇撒尿| 欧美xxxxxxxxx| 不卡的av电影在线观看| 亚洲电影中文字幕在线观看| 26uuu色噜噜精品一区| av网站免费线看精品| 亚洲www啪成人一区二区麻豆| 精品日韩一区二区三区| 99久久婷婷国产综合精品| 日韩高清在线观看| 国产精品理伦片| 在线综合视频播放| www.亚洲精品| 日本欧洲一区二区| 亚洲三级小视频| 日韩视频免费观看高清完整版| eeuss国产一区二区三区| 日韩成人免费看| 亚洲少妇30p| 久久综合五月天婷婷伊人| 欧美亚洲一区三区| 国产91精品精华液一区二区三区| 亚洲h在线观看| 中文字幕精品一区二区三区精品| 777午夜精品免费视频| 99久久99久久综合| 国产在线日韩欧美| 蜜乳av一区二区三区|