• 使用装饰设计模式加密数据


    使用装饰设计模式加密数据:

    package com.zs.JiaJiE09;
    
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    /**
     * 使用装饰设计模式把数据取反进行加密解密
     * Key方法为钥匙
     *
     * @author LZG
     *
     */
    
    public class JMOutputStream extends OutputStream{
    /**
     * 更多资料欢迎浏览凯哥学堂官网:http://kaige123.com 
    
     * @author 小沫
     */
    
    	private int key;
    	private OutputStream output;
    	public JMOutputStream(OutputStream output){
    		this.output=output;
    		
    	}
    	public void Key(int key){
    		this.key=key;
    	}
    	
    	public void write(int b) throws IOException {
    		output.write(~b+key);
    	}
    	
    	
    	public void write(byte[] b, int off, int len) throws IOException {
    		for (int i = off; i < len; i++) {
    			output.write(~b[i]+key);
    		}
    	}
    
    	public void write(byte[] b) throws IOException {
    		for (int i = 0; i < b.length; i++) {
    			output.write(~b[i]+key);
    		}
    	}
    	
    }

    测试类:

    package com.zs.JiaJiE09;
    
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class Test {
    /**
     * 更多资料欢迎浏览凯哥学堂官网:http://kaige123.com 
    
     * @author 小沫
     */
    
    	public static void main(String[] args) throws IOException{
    		
    		
    		FileInputStream fin= new FileInputStream("e:/test/aa.txt");
    		
    		JMOutputStream fout = new JMOutputStream(new FileOutputStream("d:/test/aa111.txt"));
    		fout.Key(1402);
    		byte[] b = new byte[1024];
    		
    		while(fin.available()!=0){
    			int len = fin.read(b);
    			fout.write(b, 0, len);
    		}
    		
    		fin.close();
    		fout.close();
    	}
    }
  • 相关阅读:
    Real-time 3D face tracking and reconstruction from 2D video
    Matlab Multiple View Geometry
    Multi-View 3D Reconstruction
    Scene Reconstruction
    OpenCV C++ Stereo Fisheye Calibration
    史上最全的Matlab资源电子书教程和视频下载合集
    CF-Based-Recommendation
    语种识别工具
    gdb调试
    C语言常见的函数调用
  • 原文地址:https://www.cnblogs.com/kaigexuetang/p/7197031.html
Copyright © 2020-2023  润新知