使用java脚本编码和解码html页面(使用base64)
问题描述:
我用Java做了这个我想用javascript解码html页面样本会很好
i have done this with Java i want to decode the html pages using javascript a sample will be good
package encrypt;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
*
* @author GAYAN
*/
public class Encrypt {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
File n = new File("C:\\Users\\Shashika\\Desktop\\enc");
File[] listFiles = n.listFiles();
for (File file : listFiles) {
InputStream is = null;
OutputStream os = null;
try {
BASE64Encoder bs = new BASE64Encoder();
System.out.println(file.getName());
is = new FileInputStream(file);
// os=new FileOutputStream(file);
byte[] bs1 = null;
try {
bs1 = new byte[is.available()];
System.out.println("read="+is.available());
is.read(bs1);
String encode = bs.encode(bs1);
System.out.println(encode);
is.close();
os=new FileOutputStream(file);
os.write(encode.getBytes());
os.close();
System.out.println("=====================decoding========================");
BASE64Decoder decoder=new BASE64Decoder();
byte[] decodeBuffer = decoder.decodeBuffer(new FileInputStream(file));
String s=new String(decodeBuffer);
System.out.println(s);
File f=new File("C:\\Users\\Shashika\\Desktop\\enc\\enc0000.html");
OutputStream os1=new FileOutputStream(f);
os1.write(decodeBuffer);
os1.flush();
os1.close();
// for (byte b : bs1) {
// System.out.println("byte="+b);
// }
} catch (Exception ex) {
Logger.getLogger(Encrypt.class.getName()).log(Level.SEVERE, null, ex);
}
break;
} // bs.encode();
catch (FileNotFoundException ex) {
Logger.getLogger(Encrypt.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
is.close();
} catch (IOException ex) {
Logger.getLogger(Encrypt.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
// bs.encode();
}
}
答
这是使用JavaScript的Base64编码器和解码器 [ ^ ]
您可以读取文件JS [ ^ ]并执行使用读取数据的操作,但您无法使用JS写入本地磁盘(除了Google Gears等少数例外)
Best ,
H
Here is a Base64 Encoder and Decoder with JavaScript[^]
You can read files in JS [^]and perform actions using the read data, but you cannot write to the local disk using JS (with a few exceptions like Google Gears)
Best,
H
访问这里
http://www.hashemian.com/tools/base64-encode-decode.php [ ^ ]