Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java Security  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载?
qxszjj



发贴: 0
积分: 0
于 2004-05-17 13:01 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载?

谢谢



作者 Re:DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载? [Re:qxszjj]
menzy



版主


发贴: 754
积分: 113
于 2004-06-03 09:25 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看看java的源程序。
c的源程序应当可以google到

testdes.java (2.56k)


menzy edited on 2004-06-03 09:50

作者 加密解密javabean [Re:menzy]
ewighell



发贴: 0
积分: 0
于 2004-06-06 20:21 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
menzy wrote:
看看java的源程序。
c的源程序应当可以google到

楼上的,真的太感谢了
我根据你的程序作了两个类,果然很成功。你解了我的燃眉之急,谢谢你。
我做的两个也贴在这吧,所不定哪位会用到:
1. 把一个byte[] a 加密,返回加密后的byte[]
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public class encode{
public byte[] encode(byte[] a)
{
//添加新安全算法,如果用JCE就要把它添加进去
Security.addProvider(new com.sun.crypto.provider.SunJCE());
//final String Algorithm="DES"; //定义加密算法,可用 DES,DESede,Blowfish
final String Algorithm = "DES/CBC/PKCS5Padding";
try {
//生成密钥
byte[] bytes = {'e','+','s','u','%','*','4','O'};
byte[] key = new String("de$%^@#-").getBytes();
SecretKey deskey = new SecretKeySpec(key, "DES");
Cipher c1 = Cipher.getInstance (Algorithm);
IvParameterSpec ivSpec = new IvParameterSpec (bytes);
c1.init (Cipher.ENCRYPT_MODE, deskey, ivSpec);

//加密
byte[] cipherByte=c1.doFinalAngel; //cipherByte 为加密后的二进串
return cipherByte;

} catch (java.security.NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (javax.crypto.NoSuchPaddingException e2) {
e2.printStackTrace();
} catch (java.lang.Exception e3) {
e3.printStackTrace();
}
return null;
}
}

2. 将上一个类加密过的byte[]解密,返回解密后的byte[]
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public class decode{
public byte[] decode(byte[] a)
{
//添加新安全算法,如果用JCE就要把它添加进去
Security.addProvider(new com.sun.crypto.provider.SunJCE());
//final String Algorithm="DES"; //定义加密算法,可用 DES,DESede,Blowfish
final String Algorithm = "DES/CBC/PKCS5Padding";
try {
//生成密钥
byte[] bytes = {'e','+','s','u','%','*','4','O'};
byte[] key = new String("de$%^@#-").getBytes();
SecretKey deskey = new SecretKeySpec(key, "DES");
Cipher c1 = Cipher.getInstance (Algorithm);
IvParameterSpec ivSpec = new IvParameterSpec (bytes);
c1.init (Cipher.ENCRYPT_MODE, deskey, ivSpec);

//解密
c1 = Cipher.getInstance(Algorithm);
c1.init(Cipher.DECRYPT_MODE, deskey, ivSpec);
byte[] clearByte=c1.doFinalAngel; //clearByte为解密后的二进串
return clearByte;

} catch (java.security.NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (javax.crypto.NoSuchPaddingException e2) {
e2.printStackTrace();
} catch (java.lang.Exception e3) {
e3.printStackTrace();
}
return null;
}
}



作者 Re:DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载? [Re:qxszjj]
maojy2000



发贴: 0
积分: 0
于 2004-06-17 18:09 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你不是说C解密吗,怎么还是用java解密?


作者 Re:DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载? [Re:qxszjj]
jeffrey_he





发贴: 21
积分: 0
于 2004-06-28 17:50 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
可以啊,只要指定的算法是一样的,java和c都有加解密实现。



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923