关于XML文件加密(进来就有分,分不够再加)

zblaoshu1979 2006-11-01 01:19:07
我现在想加密XML文件,大家有什么好的方法和代码吗?
...全文
505 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
zwgs1985 2006-11-03
  • 打赏
  • 举报
回复
zblaoshu1979 2006-11-02
  • 打赏
  • 举报
回复
好,谢谢,我测试一下
liyouli 2006-11-02
  • 打赏
  • 举报
回复
顶.JF
xb1223 2006-11-02
  • 打赏
  • 举报
回复
强!
顶先!
xb1223 2006-11-02
  • 打赏
  • 举报
回复
强!
顶先!
xb1223 2006-11-02
  • 打赏
  • 举报
回复
强!
顶先!
hbwhwang 2006-11-01
  • 打赏
  • 举报
回复
下面的代码我测试过了,没有问题!

import java.io.*;

import javax.crypto.*;
import java.security.*;

public class DESCryptoTest {
public static void main(String[] args) {
Security.addProvider(new com.sun.crypto.provider.SunJCE());

KeyGenerator kg = null;
try {
kg = KeyGenerator.getInstance("DES", "SunJCE");

//指定密钥长度
kg.init(56);

//产生密钥
Key key = kg.generateKey();
System.out.println("Key format: " + key.getFormat());
System.out.println("Key algorithm: " + key.getAlgorithm());

//加密要用Cipher来实现
Cipher cipher = Cipher.getInstance("DES");
System.out.println("Cipher provider: " + cipher.getProvider());
System.out.println("Cipher algorithm: " + cipher.getAlgorithm());

String filename = "e:\\temp\\test.xml";
//读入并加密文件
try {
//输入流
cipher.init(Cipher.ENCRYPT_MODE, key);
BufferedInputStream in = new BufferedInputStream(new FileInputStream(filename));
//输出流
CipherOutputStream out = new CipherOutputStream(new BufferedOutputStream(new FileOutputStream("e:\\temp\\test.xml_bak")), cipher);
int i;
do {
i = in.read();
if (i != -1)
out.write(i);
}
while (i != -1);

in.close();
out.close();
System.out.println("加密文件完成!");
}
catch (Exception ey5) {
System.out.println("Error when encrypt the file");
System.exit(0);
}

try {
cipher.init(Cipher.DECRYPT_MODE, key);
//输出流
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("e:\\temp\\test2.xml"));
//输入流
CipherInputStream in = new CipherInputStream(new BufferedInputStream(
new FileInputStream("e:\\temp\\test.xml_bak")), cipher);

int i;
do {
i = in.read();
if (i != -1)
out.write(i);
}
while (i != -1);

in.close();
out.close();
System.out.println("解密文件完成!");
}
catch (Exception ey5) {
System.out.println("Error when encrypt the file");
System.exit(0);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
zblaoshu1979 2006-11-01
  • 打赏
  • 举报
回复
<?xml version="1.0" ?>
- <!-- This Listing provides the sample XML File which will be encrypted.
-->
- <purchaseOrder>
- <Order>
<BookName>Soccer For Dummies</BookName>
<ItemId>123-958-74598</ItemId>
<Quantity>500</Quantity>
</Order>
- <Payment>
<CardNo>4502-3456-3278-2011</CardNo>
<CardType>VISA</CardType>
<ValidDate>12-10-2004</ValidDate>
</Payment>
</purchaseOrder>
hbwhwang 2006-11-01
  • 打赏
  • 举报
回复
你贴个XML,让我试
zblaoshu1979 2006-11-01
  • 打赏
  • 举报
回复
我用这个程序解密了之后XML文件打不开了
zblaoshu1979 2006-11-01
  • 打赏
  • 举报
回复
好,我看一看,谢谢
zblaoshu1979 2006-11-01
  • 打赏
  • 举报
回复
用这些算法我倒是知道,就是不知道怎么实现
hbwhwang 2006-11-01
  • 打赏
  • 举报
回复
去看看我回答的这个帖子:
http://community.csdn.net/Expert/topic/4852/4852512.xml?temp=.9543726
hbwhwang 2006-11-01
  • 打赏
  • 举报
回复
如果加密强度不高,可以用对称加密算法,比如DES。如果强度需求高,可以用非对称算法,比如RSA。
zblaoshu1979 2006-11-01
  • 打赏
  • 举报
回复
如果有数据加密的方法更好,谢谢一楼
zblaoshu1979 2006-11-01
  • 打赏
  • 举报
回复
就加密文件就行
hbwhwang 2006-11-01
  • 打赏
  • 举报
回复
是想加密整个XML文件,还是加密里面的数据?

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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