wangchao.org
添加收藏 | 博客
 
购物视频论坛IT业界自然风光美女图片王朝网络小游戏BT下载生活百科编程设计手机图铃小说
 
笑话 | 水库 | 娱乐 | 体育 | 英语 | 宠物 | 美食 | 旅游 | 养生 | 手机 | 数码 | 汽车 | 珠宝 | 美容 | 装修 | 厨房 | 科普 | 动物 | 植物 | 影音 | 百科 | 知道 | 词典
  
 
 您好! 您现在位于: 王朝网络 → 编程设计 → 《java版的MD5返回上一页 
 
1楼 

java版的MD5

  网上购物、在线购物、购物搜索 欢迎光临本站购买图书、影视、音乐、数码、百货,手机等商品。

  public class MD5
  {
   /*
   * A Java implementation of the RSA Data Security, Inc. MD5 Message
   * Digest Algorithm, as defined in RFC 1321.
   * Based on the javascript implementation of Paul Johnston
   * Copyright (C) Paul Johnston 1999 - 2000.
   * See http://pajhome.org.uk/site/legal.Html for details.
   * Java Version by Thomas Weber (Orange Interactive GmbH)
   */
  
   /*
   * Convert a 32-bit number to a hex string with ls-byte first
   */
   String hex_chr = "0123456789abcdef";
   private String rhex(int num)
   {
   String str = "";
   for(int j = 0; j <= 3; j++)
   str = str + hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) + hex_chr.charAt((num >> (j * 8)) & 0x0F);
   return str;
   }
  
   /*
   * Convert a string to a sequence of 16-Word blocks, stored as an array.
   * Append padding bits and the length, as described in the MD5 standard.
   */
   private int[] str2blks_MD5(String str)
   {
   int nblk = ((str.length() + 8) >> 6) + 1;
   int[] blks = new int[nblk * 16];
   int i = 0;
   for(i = 0; i < nblk * 16; i++) {
   blks[i] = 0;
   }
   for(i = 0; i < str.length(); i++) {
   blks[i >> 2] = str.charAt(i) << ((i % 4) * 8);
   }
   blks[i >> 2] = 0x80 << ((i % 4) * 8);
   blks[nblk * 16 - 2] = str.length()*8;
  
   return blks;
   }
  
   /*
   * Add integers, wrapping at 2^32
   */
   private int add(int x, int y)
   {
   return ((x&0x7FFFFFFF) + (y&0x7FFFFFFF)) ^ (x&0x80000000) ^ (y&0x80000000);
   }
  
   /*
   * Bitwise rotate a 32-bit number to the left
   */
   private int rol(int num, int cnt)
   {
   return (num << cnt) (num >>> (32 - cnt));
   }
  
   /*
   * These functions implement the basic operation for each round of the
   * algorithm.
   */
   private int cmn(int q, int a, int b, int x, int s, int t)
   {
   return add(rol(add(add(a, q), add(x, t)), s), b);
   }
   private int ff(int a, int b, int c, int d, int x, int s, int t)
   {
   return cmn((b & c) ((~b) & d), a, b, x, s, t);
   }
   private int gg(int a, int b, int c, int d, int x, int s, int t)
   {
   return cmn((b & d) (c & (~d)), a, b, x, s, t);

  public class MD5 { /* * A Java implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. * Based on the javascript implementation of Paul Johnston * Copyright (C) Paul Johnston 1999 - 2000. * See http://pajhome.org.uk/site/legal.Html for details. * Java Version by Thomas Weber (Orange Interactive GmbH) */ /* * Convert a 32-bit number to a hex string with ls-byte first */ String hex_chr = "0123456789abcdef"; private String rhex(int num) { String str = ""; for(int j = 0; j <= 3; j++) str = str + hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) + hex_chr.charAt((num >> (j * 8)) & 0x0F); return str; } /* * Convert a string to a sequence of 16-Word blocks, stored as an array. * Append padding bits and the length, as described in the MD5 standard. */ private int[] str2blks_MD5(String str) { int nblk = ((str.length() + 8) >> 6) + 1; int[] blks = new int[nblk * 16]; int i = 0; for(i = 0; i < nblk * 16; i++) { blks[i] = 0; } for(i = 0; i < str.length(); i++) { blks[i >> 2] = str.charAt(i) << ((i % 4) * 8); } blks[i >> 2] = 0x80 << ((i % 4) * 8); blks[nblk * 16 - 2] = str.length()*8; return blks; } /* * Add integers, wrapping at 2^32 */ private int add(int x, int y) { return ((x&0x7FFFFFFF) + (y&0x7FFFFFFF)) ^ (x&0x80000000) ^ (y&0x80000000); } /* * Bitwise rotate a 32-bit number to the left */ private int rol(int num, int cnt) { return (num << cnt) (num >>> (32 - cnt)); } /* * These functions implement the basic operation for each round of the * algorithm. */ private int cmn(int q, int a, int b, int x, int s, int t) { return add(rol(add(add(a, q), add(x, t)), s), b); } private int ff(int a, int b, int c, int d, int x, int s, int t) { return cmn((b & c) ((~b) & d), a, b, x, s, t); } private int gg(int a, int b, int c, int d, int x, int s, int t) { return cmn((b & d) (c & (~d)), a, b, x, s, t);

 
标签: java  MD5  版的  
 
您可以将本页贴到其他网站
UBB代码HTML代码
 
 
 
 
 
 
 更多内容
 ·JavaServer Faces (JSF) vs Stru ·JavaServer Faces 简介 ·JavaVM,反射与动态代理 ·javamail的几个实用知识点
 ·JavaMail邮件主题乱码的解决方法 ·javamail中使用发信身份验证 ·javaRMI使用入门程序及配置 ·Javadoc 利弊分析(from IBM)
 ·Java--ImageViewer ·javaCC学习笔记 ·JavaBean 设置关联属性 ·JavaBean调用示例(转)
 ·JavaBean与EJB的不同 ·JavaCC的安装 ·Java的建造设计模式 ·Java的魔力:字节码
 ·JAVA的动态编译和静态编译 ·Java的Package与Import机制之我的 ·Java的产生 ·java的io系统
 ·Java的Build工具—Ant应用指南( ·java的io简单应用 ·java的io简单应用 选择自 FrankT ·Java单体测试工具cactus使用指南
 
 
最新评论  点此查看所有评论
 
 
 
 
发表评论(支持UBB码)


验证码:  
 
 
 
© 2005- 王朝网络 版权所有