本站首页    管理页面    写新日志    退出


«July 2025»
12345
6789101112
13141516171819
20212223242526
2728293031


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7569879
建立时间:2006年5月29日




[算法]用DES加密字符串(转载)
软件技术,  电脑与网络

lhwork 发表于 2006/6/21 13:51:40

import java.io.*;import java.security.*;import javax.crypto.*;import sun.misc.BASE64Encoder; public class DES { public static byte[] aa; public static void main(String[] args) throws Exception {  if (args.length < 3) {   System.out.println("Usage: java PwdDES -e|-d passwd input");   return;  }  Key key;  KeyGenerator generator = KeyGenerator.getInstance("DES");  generator.init(new SecureRandom(args[1].getBytes()));  key = generator.generateKey();   Cipher cipher = Cipher.getInstance("DES");   if (args[0].indexOf("e") != -1)   cipher.init(Cipher.ENCRYPT_MODE, key);  else   cipher.init(Cipher.DECRYPT_MODE, key);   System.out.println(new String(args[2].getBytes()));  System.out.println(crypt(args[2].getBytes(),cipher));    cipher.init(Cipher.DECRYPT_MODE, key);  System.out.println(crypt(aa,cipher)); } private static String crypt(byte[] bt,Cipher cipher)throws IOException,GeneralSecurityException{  BASE64Encoder be = new BASE64Encoder();        byte[] outBytes = new byte[1024];        int inLength = 0;        inLength = bt.length;        if(inLength > 0)   outBytes = cipher.doFinal(bt,0,inLength);        else            outBytes = cipher.doFinal();        aa = outBytes;  return new String(outBytes);    }}


阅读全文(2016) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.063 second(s), page refreshed 144769843 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号