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

📄 des_encrypt.java.bak

📁 DESedeCBC实验
💻 BAK
字号:
import java.io.*;
import java.util.*;
import javax.crypto.*;
import java.security.*;
import javax.crypto.spec.*;

public class DES_encrypt
{
	public static void main(String arg[])  throws Exception
	{
		System.out.println("Encrypt the \"ptext1.dat\" to \"ctext.dat\".");
		
				
		    FileInputStream f=new FileInputStream("key1.dat");
			ObjectInputStream ob=new ObjectInputStream(f);
			Key k=(Key)ob.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);
            FileInputStream fin=new FileInputStream("ptext1.dat");
			CipherInputStream cin=new CipherInputStream(fin, cp);
			
			FileOutputStream fout=new FileOutputStream("ctext.dat");
	
            
			
			int b=0;
			while( (b=cin.read())!=-1)
			{
				fout.write(b);
				//System.out.print((char)b);
				System.out.print((byte)b+",");
			}
			FileOutputStream f2=new FileOutputStream("SEncCBC.dat");
            f2.write(rand);
		
	}
}

⌨️ 快捷键说明

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