• java 简单xor加密


    java端加密文件

    package enc;

    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;

    public class Enc {

        public void encryptFile(){
             FileInputStream in = null;
             FileOutputStream out = null;
             try {
                 String sourceFileUrl = "H:\cookie\app\src\main\assets\login.js";
                 String targetFileUrl = "H:\cookie\app\src\main\assets\login_enc.js";
                 in = new FileInputStream(sourceFileUrl);
                 out = new FileOutputStream(targetFileUrl);
                 int data = 0;
                 while ((data=in.read())!=-1){
                     //将读取到的字节异或上一个数,加密输出
                     out.write(data^5);
                 }
             }catch (Exception e){
                 e.printStackTrace();
             }finally {
                 //在finally中关闭开启的流
                 if (in!=null){
                     try {
                         in.close();
                     } catch (IOException e) {
                         e.printStackTrace();
                     }
                 }
                 if (out!=null){
                     try {
                         out.close();
                     } catch (IOException e) {
                         e.printStackTrace();
                     }
                 }
             }
         }
            
             public static void main(String[] args) {
                 System.out.println("Hello, world!");
                 Enc enc = new Enc();
                 enc.encryptFile();
             }
    }



    android端解密

        private static byte[]  endecrypt(int seed,byte[] bytes){//seed为加密种子,str为加密对象
    for(int i = 0;i<bytes.length;i++){
    bytes[i] ^= seed;
    }
    return bytes;
    }

    // 加载本地 assets 的 js
    public static void injectScriptFile(WebView webView, String filePath) {
    InputStream input;
    try {
    input = webView.getContext().getAssets().open(filePath);
    byte[] buffer = new byte[input.available()];
    input.read(buffer);
    input.close();

    buffer = endecrypt(5, buffer);
    // Log.e("xxxxx", new String(buffer));
    }
        catch (IOException e) {
    Log.e(TAG, "injectScriptFile: " + e);
    }
  • 相关阅读:
    《区块链100问》第38集:比特币钱包是干嘛的?
    《区块链100问》第39集:冷钱包热钱包
    《区块链100问》第40集:全节点钱包和轻钱包
    《区块链100问》第41集:比特币可以用于支付吗?
    《区块链100问》第42集:区块链和比特币的关系
    《区块链100问》第43集:区块链技术发展史
    KindEditor使用
    Django之验证码
    Django之ModelForm
    Django之Form详解
  • 原文地址:https://www.cnblogs.com/cute/p/13303740.html
Copyright © 2020-2023  润新知