java xor_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[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);
}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的java xor_java 简单xor加密的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU 5410 CRB and His
- 下一篇: materialrefeshlayout