前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >java xor_java 简单xor加密[通俗易懂]

java xor_java 简单xor加密[通俗易懂]

作者头像
全栈程序员站长
发布2022-09-13 10:56:11
7020
发布2022-09-13 10:56:11
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

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[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);

}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/160189.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档