nedoPC.org

Electronics hobbyists community established in 2002
Atom Feed | View unanswered posts | View active topics It is currently 28 Mar 2024 13:36



This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
MD5 на Java 
Author Message
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Получение строкового представления MD5 из произвольной строки на языке Java:

Code:
  import java.security.MessageDigest;
   ...
  String buf = "..."; // входная строка
  String md5 = null; // выходная строка
  try {
    char Hex[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
    MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(buf.getBytes());
    byte[] digest = md.digest();
    StringBuffer sb = new StringBuffer();
    for(int i=0;i<digest.length;i++)
    {
      sb.append(Hex[(digest[i]>>4)&15]);
      sb.append(Hex[digest[i]&15]);
    }
    md5 = new String(sb);   
  } catch(Exception e) { }


Может кому полезно будет. Этот код используется в веб-модуле авторизации для сайта rwar.net.

_________________
:dj: https://mastodon.social/@Shaos


24 Feb 2005 21:39
Profile WWW
Display posts from previous:  Sort by  
This topic is locked, you cannot edit posts or make further replies.   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.