Topic: DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载? |
Print this page |
1.DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载? | Copy to clipboard |
Posted by: qxszjj Posted on: 2004-05-17 13:01 DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载? 谢谢 |
2.Re:DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载? [Re: qxszjj] | Copy to clipboard |
Posted by: menzy Posted on: 2004-06-03 09:25 看看java的源程序。 c的源程序应当可以google到 testdes.java (2.56k) |
3.加密解密javabean [Re: menzy] | Copy to clipboard |
Posted by: ewighell Posted on: 2004-06-06 20:21 menzy wrote: 楼上的,真的太感谢了 我根据你的程序作了两个类,果然很成功。你解了我的燃眉之急,谢谢你。 我做的两个也贴在这吧,所不定哪位会用到: 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.doFinal; //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.doFinal; //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; } } |
4.Re:DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载? [Re: qxszjj] | Copy to clipboard |
Posted by: maojy2000 Posted on: 2004-06-17 18:09 你不是说C解密吗,怎么还是用java解密? |
5.Re:DES ,java进行加密,linux C进行解密 可行吗,哪里有相应两个代码下载? [Re: qxszjj] | Copy to clipboard |
Posted by: jeffrey_he Posted on: 2004-06-28 17:50 可以啊,只要指定的算法是一样的,java和c都有加解密实现。 |
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 |