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

java xor_java 简单xor加密[通俗易懂]java端加密文件packageenc;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.IOException;publicclassEnc{publicvoidencryptFile(){FileInputStreamin=null;FileOutputStreamou…

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

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.net/160189.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号