android平台上的加密程序源代码

liujuhero 2010-12-07 11:41:08
哪位朋友能够不吝赐教一个个android平台上的加密程序啊,就是加密文件的那种,小弟在这里先行谢过了!献上全部分值!
...全文
262 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
juanmaolang001 2011-08-10
  • 打赏
  • 举报
回复
解密呢。。。
[Quote=引用 3 楼 woshayawo 的回复:]
package day20.editor;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class FileEncrypt {
public static void main(String[] args) {
new FileEncr……
[/Quote]
woshayawo 2010-12-09
  • 打赏
  • 举报
回复
package day20.editor;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class FileEncrypt {
public static void main(String[] args) {
new FileEncryptFrame().init();
}
}


class FileEncryptFrame extends JFrame{
JPanel jp1;
JPanel jp2;
JLabel jlb1;
JLabel jlb2;
JFileChooser jfc;
JCheckBox jcb;
JTextField jtf;
JButton jb1;
JButton jb2;
JProgressBar jpb;
class RefreshProgressBarThread extends Thread{
public RefreshProgressBarThread(){

}

public void run(){

}
}
public FileEncryptFrame(){
super("文件加密/解密器 v1.0");
jp1=new JPanel();
jp2=new JPanel();
jlb1=new JLabel("选择要加密/解密的文件:");
jlb2=new JLabel("选择加密/解密算子(0-255):");
jfc=new JFileChooser();
jtf=new JTextField(10);
jcb=new JCheckBox("覆盖原文件");
jb1=new JButton("加密/解密");
jb2=new JButton("取消");
jpb=new JProgressBar();
jpb.setStringPainted(true);
}

public void init(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
this.setLayout(new BorderLayout());
this.add(jp1,BorderLayout.CENTER);
this.add(jp2,BorderLayout.SOUTH);

jp1.setAlignmentX(JPanel.LEFT_ALIGNMENT);
jp1.setLayout(new FlowLayout(FlowLayout.LEFT));
jfc.setControlButtonsAreShown(false);
jp1.add(jlb1);
jp1.add(jfc);
jp1.add(jlb2);
jp1.add(jtf);
jp1.add(jcb);
jp1.add(jpb);

jp2.add(jb1);
jp2.add(jb2);

setVisible(true);
setSize(520,480);
this.setResizable(false);
setEvent();
}
public void setEvent(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
File f=jfc.getSelectedFile();
int code=Integer.parseInt(jtf.getText());
new Encrypter(code,f,jcb.isSelected()).encode();
final JDialog jd=new JDialog(FileEncryptFrame.this,"加密成功!");
jd.add(new JLabel("文件加密成功!"),BorderLayout.NORTH);
JButton jbok;
jd.add(jbok=new JButton("确定"),BorderLayout.SOUTH);
jbok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jd.dispose();
}
});
jd.setLocationRelativeTo(FileEncryptFrame.this);
jd.setSize(300,200);
jd.setVisible(true);
}
});

jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);}
});
}
}

class Encrypter{
int code;
boolean rewrite;
File sourceFile;
FileInputStream fin;
FileOutputStream fout;
String sourceFileName;
String objFileName;

public Encrypter(int c,File file,boolean rewrite)
{ code=c;
sourceFile=file;
this.rewrite=rewrite;
sourceFileName=sourceFile.getAbsolutePath();
System.out.print(sourceFileName);
int indexOfDot=sourceFileName.lastIndexOf('.');
System.out.print(indexOfDot);
if(indexOfDot==-1){//如果原文件名不包含扩展名
objFileName=sourceFileName+".sec";
}else {//如果原文件名包含扩展名
String postfixName=sourceFileName.substring(indexOfDot);
if(postfixName.equals(".sec")){//如果扩展名是.sec
objFileName=sourceFileName.substring(0,indexOfDot);
}else{
objFileName=sourceFileName+".sec";
}
}
}
public void encode(){
if(rewrite){//覆盖原文件
RandomAccessFile fra=null;
try {
fra=new RandomAccessFile(sourceFile,"rw");
int temp;
while((temp=fra.read())!=-1){
fra.seek(fra.getFilePointer()-1);
fra.write(temp^code);
}
//System.out.println(objFileName);
//System.out.println(sourceFile.renameTo(new File("objFileName")));
} catch (Exception e) {
e.printStackTrace();
}finally{
if(fra!=null)try{fra.close();}catch(IOException e){}
}
}else{//不覆盖原文件
FileInputStream fis=null;
FileOutputStream fos=null;
try {
fis=new FileInputStream(sourceFile);
fos=new FileOutputStream(objFileName);
while(fis.available()>0){
fos.write(fis.read()^code);
}
fos.flush();
} catch (Exception e) {
e.printStackTrace();
}finally{
if(fis!=null)try{fis.close();}catch(IOException e){}
if(fos!=null)try{fos.close();}catch(IOException e){}
}
}

}
}
ameyume 2010-12-08
  • 打赏
  • 举报
回复
java上的加密算法就可以吧?
应该很多这种程序
妖怪 2010-12-07
  • 打赏
  • 举报
回复
你想用什么方式加密?
MD5? 还是?

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧