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

📄 main.java

📁 AES,DES,RSA,SHA1四个加密解密算法。
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package AES;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;/** * * @author Fredrik */public class Main {    /**     * @param args the command line arguments     * @throws IOException      */    //example of encryption decryption from the AES standard document    public static void main(String[] args) throws IOException {    			       					 byte[] key2={(byte)0x00,(byte)0x01,(byte)0x02,(byte)0x03,	                   (byte)0x04,(byte)0x05,(byte)0x06,(byte)0x07,	                   (byte)0x08,(byte)0x09,(byte)0x0a,(byte)0x0b,	                   (byte)0x0c,(byte)0x0d,(byte)0x0e,(byte)0x0f};	        String filename = "D:\\My Documents\\test.JPG";	        File sourceFile = new File(filename);	        String enfile = filename + ".encrypt";	        File encryptfile = new File(enfile);	        int fileSize = (int) (sourceFile.length());	        int block = ((int) (fileSize / 16)) + 1 ;	        fileSize = 16 * block ;	        byte[] buff = new byte[fileSize];	        byte[] ciphertext = new byte[16];			byte[] temp = new byte[16];			FileOutputStream out = null;			FileInputStream in = new FileInputStream(sourceFile);			in.read(buff);			in.close();			AES cipher = new AES(key2);			//加密开始			long begin = System.currentTimeMillis();//计时开始			for(int j = 0 ; j<block ; j++){	        	for(int k=0 ; k<16 ; k++)	{	        		temp[k] = buff[j*16+k];		        			        	}	        	ciphertext=cipher.encrypt(temp);	        	for(int k=0 ; k<16 ; k++){	        		buff[j*16+k] = ciphertext[k];	        	}	        }			out = new FileOutputStream(encryptfile);			out.write(buff);			out.close();			long current = System.currentTimeMillis();			System.out.println((current - begin) + " ms");//计时结束			System.out.println("Encrypt Success!");			//加密结束			in = new FileInputStream(encryptfile);			in.read(buff);							in.close();						String defile = filename + ".decrypt";	        File decryptfile = new File(defile);			//解密开始	        begin = System.currentTimeMillis();//计时开始			for(int j = 0 ; j<block ; j++){	        	for(int k=0 ; k<16 ; k++)	{	        		temp[k] = buff[j*16+k];		        			        	}	        	ciphertext=cipher.decrypt(temp);	        	for(int k=0 ; k<16 ; k++){	        		buff[j*16+k] = ciphertext[k];	        	}	        }			out = new FileOutputStream(decryptfile);			out.write(buff);			out.close();			current = System.currentTimeMillis();			System.out.println((current - begin) + " ms");//计时结束			System.out.println("Decrypt Success!");		                                               }}

⌨️ 快捷键说明

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