<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSecurity%2FMD5_String</id>
		<title>Java/Security/MD5 String - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSecurity%2FMD5_String"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Security/MD5_String&amp;action=history"/>
		<updated>2026-04-21T17:24:16Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Security/MD5_String&amp;diff=7663&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Security/MD5_String&amp;diff=7663&amp;oldid=prev"/>
				<updated>2010-06-01T06:49:29Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:49, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Security/MD5_String&amp;diff=7662&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Security/MD5_String&amp;diff=7662&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Encode an MD5 digest into a String. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
/*&lt;br /&gt;
 * Licensed to the Apache Software Foundation (ASF) under one or more&lt;br /&gt;
 * contributor license agreements.  See the NOTICE file distributed with&lt;br /&gt;
 * this work for additional information regarding copyright ownership.&lt;br /&gt;
 * The ASF licenses this file to You under the Apache License, Version 2.0&lt;br /&gt;
 * (the &amp;quot;License&amp;quot;); you may not use this file except in compliance with&lt;br /&gt;
 * the License.  You may obtain a copy of the License at&lt;br /&gt;
 * &lt;br /&gt;
 *      http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 * &lt;br /&gt;
 * Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
 * distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
 * See the License for the specific language governing permissions and&lt;br /&gt;
 * limitations under the License.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Encode an MD5 digest into a String.&lt;br /&gt;
 * &amp;lt;p&amp;gt;&lt;br /&gt;
 * The 128 bit MD5 hash is converted into a 32 character long String.&lt;br /&gt;
 * Each character of the String is the hexadecimal representation of 4 bits&lt;br /&gt;
 * of the digest.&lt;br /&gt;
 *&lt;br /&gt;
 * @author Remy Maucherat&lt;br /&gt;
 * @version $Revision: 515 $ $Date: 2008-03-17 22:02:23 +0100 (Mon, 17 Mar 2008) $&lt;br /&gt;
 */&lt;br /&gt;
public final class MD5Encoder {&lt;br /&gt;
&lt;br /&gt;
    // ----------------------------------------------------- Instance Variables&lt;br /&gt;
&lt;br /&gt;
    private static final char[] hexadecimal =&lt;br /&gt;
    {&amp;quot;0&amp;quot;, &amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;, &amp;quot;3&amp;quot;, &amp;quot;4&amp;quot;, &amp;quot;5&amp;quot;, &amp;quot;6&amp;quot;, &amp;quot;7&amp;quot;, &amp;quot;8&amp;quot;, &amp;quot;9&amp;quot;,&lt;br /&gt;
     &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;d&amp;quot;, &amp;quot;e&amp;quot;, &amp;quot;f&amp;quot;};&lt;br /&gt;
&lt;br /&gt;
    // --------------------------------------------------------- Public Methods&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Encodes the 128 bit (16 bytes) MD5 into a 32 character String.&lt;br /&gt;
     *&lt;br /&gt;
     * @param binaryData Array containing the digest&lt;br /&gt;
     * @return Encoded MD5, or null if encoding failed&lt;br /&gt;
     */&lt;br /&gt;
    public String encode( byte[] binaryData ) {&lt;br /&gt;
        if (binaryData.length != 16)&lt;br /&gt;
            return null;&lt;br /&gt;
        char[] buffer = new char[32];&lt;br /&gt;
        for (int i=0; i&amp;lt;16; i++) {&lt;br /&gt;
            int low = (int) (binaryData[i] &amp;amp; 0x0f);&lt;br /&gt;
            int high = (int) ((binaryData[i] &amp;amp; 0xf0) &amp;gt;&amp;gt; 4);&lt;br /&gt;
            buffer[i*2] = hexadecimal[high];&lt;br /&gt;
            buffer[i*2 + 1] = hexadecimal[low];&lt;br /&gt;
        }&lt;br /&gt;
        return new String(buffer);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Get MD5 Base64 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
/*&lt;br /&gt;
 * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/util/MD5.java,v 1.6 2007/01/15 10:27:31 dungbtm Exp $&lt;br /&gt;
 * $Author: dungbtm $&lt;br /&gt;
 * $Revision: 1.6 $&lt;br /&gt;
 * $Date: 2007/01/15 10:27:31 $&lt;br /&gt;
 *&lt;br /&gt;
 * &lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (C) 2002-2007 by MyVietnam.net&lt;br /&gt;
 *&lt;br /&gt;
 * All copyright notices regarding mvnForum MUST remain &lt;br /&gt;
 * intact in the scripts and in the outputted HTML.&lt;br /&gt;
 * The &amp;quot;powered by&amp;quot; text/logo with a link back to&lt;br /&gt;
 * http://www.mvnForum.ru and http://www.MyVietnam.net in &lt;br /&gt;
 * the footer of the pages MUST remain visible when the pages&lt;br /&gt;
 * are viewed on the internet or intranet.&lt;br /&gt;
 *&lt;br /&gt;
 * This program is free software; you can redistribute it and/or modify&lt;br /&gt;
 * it under the terms of the GNU General Public License as published by&lt;br /&gt;
 * the Free Software Foundation; either version 2 of the License, or&lt;br /&gt;
 * any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This program is distributed in the hope that it will be useful,&lt;br /&gt;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
 * GNU General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU General Public License&lt;br /&gt;
 * along with this program; if not, write to the Free Software&lt;br /&gt;
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA&lt;br /&gt;
 *&lt;br /&gt;
 * Support can be obtained from support forums at:&lt;br /&gt;
 * http://www.mvnForum.ru/mvnforum/index&lt;br /&gt;
 *&lt;br /&gt;
 * Correspondence and Marketing Questions can be sent to:&lt;br /&gt;
 * info at MyVietnam net&lt;br /&gt;
 *&lt;br /&gt;
 * @author: &lt;br /&gt;
 */&lt;br /&gt;
import java.io.UnsupportedEncodingException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
//&lt;br /&gt;
//  The JavaReference.ru Software License, Version 1.0 &lt;br /&gt;
//  Copyright (c) 2002-2005  JavaReference.ru. All rights reserved.&lt;br /&gt;
//&lt;br /&gt;
//  &lt;br /&gt;
//  Redistribution and use in source and binary forms, with or without &lt;br /&gt;
//  modification, are permitted provided that the following conditions &lt;br /&gt;
//  are met: &lt;br /&gt;
//  &lt;br /&gt;
//  1. Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
//     this list of conditions and the following disclaimer. &lt;br /&gt;
//  &lt;br /&gt;
//  2. Redistributions in binary form must reproduce the above copyright notice, &lt;br /&gt;
//     this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
//     and/or other materials provided with the distribution. &lt;br /&gt;
//     &lt;br /&gt;
//  3. The end-user documentation included with the redistribution, if any, must &lt;br /&gt;
//     include the following acknowlegement: &lt;br /&gt;
//     &lt;br /&gt;
//     &amp;quot;This product includes software developed by the Javareference.ru &lt;br /&gt;
//     (http://www.javareference.ru/).&amp;quot; &lt;br /&gt;
//     &lt;br /&gt;
//     Alternately, this acknowlegement may appear in the software itself, if and &lt;br /&gt;
//     wherever such third-party acknowlegements normally appear. &lt;br /&gt;
//     &lt;br /&gt;
//  4. The names &amp;quot;JavaReference&amp;quot; and &amp;quot;Javareference.ru&amp;quot;, must not be used to &lt;br /&gt;
//     endorse or promote products derived from this software without prior written &lt;br /&gt;
//     permission. For written permission, please contact webmaster@javareference.ru. &lt;br /&gt;
//     &lt;br /&gt;
//  5. Products derived from this software may not be called &amp;quot;Javareference&amp;quot; nor may &lt;br /&gt;
//     &amp;quot;Javareference&amp;quot; appear in their names without prior written permission of  &lt;br /&gt;
//     Javareference.ru. &lt;br /&gt;
//     &lt;br /&gt;
//  THIS SOFTWARE IS PROVIDED ``AS IS&amp;quot;&amp;quot; AND ANY EXPRESSED OR IMPLIED WARRANTIES, &lt;br /&gt;
//  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND &lt;br /&gt;
//  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL &lt;br /&gt;
//  JAVAREFERENCE.ru OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, &lt;br /&gt;
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT &lt;br /&gt;
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR &lt;br /&gt;
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF &lt;br /&gt;
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING &lt;br /&gt;
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, &lt;br /&gt;
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. &lt;br /&gt;
//  &lt;br /&gt;
//&lt;br /&gt;
//  Software from this site consists of contributions made by various individuals &lt;br /&gt;
//  on behalf of Javareference.ru. For more information on Javareference.ru, &lt;br /&gt;
//  please see http://www.javareference.ru &lt;br /&gt;
//&lt;br /&gt;
/**&lt;br /&gt;
 * @author anandh&lt;br /&gt;
 */&lt;br /&gt;
public class MD5 {&lt;br /&gt;
    static char[] carr = { &amp;quot;0&amp;quot;, &amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;, &amp;quot;3&amp;quot;, &amp;quot;4&amp;quot;, &amp;quot;5&amp;quot;, &amp;quot;6&amp;quot;, &amp;quot;7&amp;quot;, &amp;quot;8&amp;quot;, &amp;quot;9&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, &amp;quot;d&amp;quot;, &amp;quot;e&amp;quot;, &amp;quot;f&amp;quot; };&lt;br /&gt;
    public static String getBase64FromHEX(String input) {&lt;br /&gt;
        &lt;br /&gt;
        byte barr[] = new byte[16];&lt;br /&gt;
        int bcnt = 0;&lt;br /&gt;
        for (int i = 0; i &amp;lt; 32; i += 2) {&lt;br /&gt;
            char c1 = input.charAt(i);&lt;br /&gt;
            char c2 = input.charAt(i + 1);&lt;br /&gt;
            int i1 = intFromChar(c1);&lt;br /&gt;
            int i2 = intFromChar(c2);&lt;br /&gt;
            barr[bcnt] = 0;&lt;br /&gt;
            barr[bcnt] |= (byte) ((i1 &amp;amp; 0x0F) &amp;lt;&amp;lt; 4);&lt;br /&gt;
            barr[bcnt] |= (byte) (i2 &amp;amp; 0x0F);&lt;br /&gt;
            bcnt++;&lt;br /&gt;
        }&lt;br /&gt;
        BASE64Encoder encoder = new BASE64Encoder();&lt;br /&gt;
        return encoder.encode(barr);&lt;br /&gt;
    }&lt;br /&gt;
    public static synchronized String getMD5_Base64(String input) {&lt;br /&gt;
        // please note that we dont use digest, because if we&lt;br /&gt;
        // cannot get digest, then the second time we have to call it&lt;br /&gt;
        // again, which will fail again&lt;br /&gt;
        MessageDigest digest = null;&lt;br /&gt;
        try {&lt;br /&gt;
            digest = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
        } catch (Exception ex) {&lt;br /&gt;
            ex.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        if (digest == null)&lt;br /&gt;
            return input;&lt;br /&gt;
        // now everything is ok, go ahead&lt;br /&gt;
        try {&lt;br /&gt;
            digest.update(input.getBytes(&amp;quot;UTF-8&amp;quot;));&lt;br /&gt;
        } catch (java.io.UnsupportedEncodingException ex) {&lt;br /&gt;
            ex.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        byte[] rawData = digest.digest();&lt;br /&gt;
        BASE64Encoder bencoder = new BASE64Encoder();&lt;br /&gt;
        return bencoder.encode(rawData);&lt;br /&gt;
    }&lt;br /&gt;
    private static int intFromChar(char c) {&lt;br /&gt;
        char clower = Character.toLowerCase(c);&lt;br /&gt;
        for (int i = 0; i &amp;lt; carr.length; i++) {&lt;br /&gt;
            if (clower == carr[i]) {&lt;br /&gt;
                return i;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        &lt;br /&gt;
        //String password = args[0];&lt;br /&gt;
        String password = &amp;quot;test&amp;quot;;&lt;br /&gt;
        MessageDigest digest = null;&lt;br /&gt;
        try {&lt;br /&gt;
            digest = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
        } catch (NoSuchAlgorithmException e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        try {&lt;br /&gt;
            digest.update(password.getBytes(&amp;quot;UTF-8&amp;quot;));&lt;br /&gt;
        } catch (UnsupportedEncodingException ex) {&lt;br /&gt;
            ex.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
        byte[] rawData = digest.digest();&lt;br /&gt;
        StringBuffer printable = new StringBuffer();&lt;br /&gt;
        for (int i = 0; i &amp;lt; rawData.length; i++) {&lt;br /&gt;
            printable.append(carr[((rawData[i] &amp;amp; 0xF0) &amp;gt;&amp;gt; 4)]);&lt;br /&gt;
            printable.append(carr[(rawData[i] &amp;amp; 0x0F)]);&lt;br /&gt;
        }&lt;br /&gt;
        String phpbbPassword = printable.toString();&lt;br /&gt;
        System.out.println(&amp;quot;PHPBB           : &amp;quot; + phpbbPassword);&lt;br /&gt;
        System.out.println(&amp;quot;MVNFORUM        : &amp;quot; + getMD5_Base64(password));&lt;br /&gt;
        System.out.println(&amp;quot;PHPBB-&amp;gt;MVNFORUM : &amp;quot; + getBase64FromHEX(phpbbPassword));&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Security Utils ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
/**&lt;br /&gt;
 * Copyright 2005-2008 Noelios Technologies.&lt;br /&gt;
 * &lt;br /&gt;
 * The contents of this file are subject to the terms of the following open&lt;br /&gt;
 * source licenses: LGPL 3.0 or LGPL 2.1 or CDDL 1.0 (the &amp;quot;Licenses&amp;quot;). You can&lt;br /&gt;
 * select the license that you prefer but you may not use this file except in&lt;br /&gt;
 * compliance with one of these Licenses.&lt;br /&gt;
 * &lt;br /&gt;
 * You can obtain a copy of the LGPL 3.0 license at&lt;br /&gt;
 * http://www.gnu.org/licenses/lgpl-3.0.html&lt;br /&gt;
 * &lt;br /&gt;
 * You can obtain a copy of the LGPL 2.1 license at&lt;br /&gt;
 * http://www.gnu.org/licenses/lgpl-2.1.html&lt;br /&gt;
 * &lt;br /&gt;
 * You can obtain a copy of the CDDL 1.0 license at&lt;br /&gt;
 * http://www.sun.ru/cddl/cddl.html&lt;br /&gt;
 * &lt;br /&gt;
 * See the Licenses for the specific language governing permissions and&lt;br /&gt;
 * limitations under the Licenses.&lt;br /&gt;
 * &lt;br /&gt;
 * Alternatively, you can obtain a royaltee free commercial license with less&lt;br /&gt;
 * limitations, transferable or non-transferable, directly at&lt;br /&gt;
 * http://www.noelios.ru/products/restlet-engine&lt;br /&gt;
 * &lt;br /&gt;
 * Restlet is a registered trademark of Noelios Technologies.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
import java.io.UnsupportedEncodingException;&lt;br /&gt;
import java.security.InvalidKeyException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.util.Arrays;&lt;br /&gt;
import javax.crypto.Mac;&lt;br /&gt;
import javax.crypto.spec.SecretKeySpec;&lt;br /&gt;
/**&lt;br /&gt;
 * Security data manipulation utilities.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Jerome Louvel&lt;br /&gt;
 */&lt;br /&gt;
public class SecurityUtils {&lt;br /&gt;
    /**&lt;br /&gt;
     * General regex pattern to extract comma separated name-value components.&lt;br /&gt;
     * This pattern captures one name and value per match(), and is repeatedly&lt;br /&gt;
     * applied to the input string to extract all components. Must handle both&lt;br /&gt;
     * quoted and unquoted values as RFC2617 isn&amp;quot;t consistent in this respect.&lt;br /&gt;
     * Pattern is immutable and thread-safe so reuse one static instance.&lt;br /&gt;
     */&lt;br /&gt;
    private static final char[] HEXDIGITS = &amp;quot;0123456789abcdef&amp;quot;.toCharArray();&lt;br /&gt;
    /**&lt;br /&gt;
     * Generates a nonce as recommended in section 3.2.1 of RFC-2617, but&lt;br /&gt;
     * without the ETag field. The format is: &amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
     * Base64.encodeBytes(currentTimeMS + &amp;amp;quot;:&amp;amp;quot;&lt;br /&gt;
     *         + md5String(currentTimeMS + &amp;amp;quot;:&amp;amp;quot; + secretKey))&lt;br /&gt;
     * &amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
     * &lt;br /&gt;
     * @param secretKey&lt;br /&gt;
     *            a secret value known only to the creator of the nonce. It&amp;quot;s&lt;br /&gt;
     *            inserted into the nonce, and can be used later to validate the&lt;br /&gt;
     *            nonce.&lt;br /&gt;
     */&lt;br /&gt;
    public static String makeNonce(String secretKey) {&lt;br /&gt;
        final long currentTimeMS = System.currentTimeMillis();&lt;br /&gt;
        return Base64.encode((currentTimeMS + &amp;quot;:&amp;quot; + toMd5(currentTimeMS + &amp;quot;:&amp;quot;&lt;br /&gt;
                + secretKey)).getBytes(), true);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Converts a source string to its HMAC/SHA-1 value.&lt;br /&gt;
     * &lt;br /&gt;
     * @param source&lt;br /&gt;
     *            The source string to convert.&lt;br /&gt;
     * @param secretKey&lt;br /&gt;
     *            The secret key to use for conversion.&lt;br /&gt;
     * @return The HMac value of the source string.&lt;br /&gt;
     */&lt;br /&gt;
    public static byte[] toHMac(String source, String secretKey) {&lt;br /&gt;
        byte[] result = null;&lt;br /&gt;
        try {&lt;br /&gt;
            // Create the HMAC/SHA1 key&lt;br /&gt;
            final SecretKeySpec signingKey = new SecretKeySpec(secretKey&lt;br /&gt;
                    .getBytes(), &amp;quot;HmacSHA1&amp;quot;);&lt;br /&gt;
            // Create the message authentication code (MAC)&lt;br /&gt;
            final Mac mac = Mac.getInstance(&amp;quot;HmacSHA1&amp;quot;);&lt;br /&gt;
            mac.init(signingKey);&lt;br /&gt;
            // Compute the HMAC value&lt;br /&gt;
            result = mac.doFinal(source.getBytes());&lt;br /&gt;
        } catch (NoSuchAlgorithmException nsae) {&lt;br /&gt;
            throw new RuntimeException(&lt;br /&gt;
                    &amp;quot;Could not find the SHA-1 algorithm. HMac conversion failed.&amp;quot;,&lt;br /&gt;
                    nsae);&lt;br /&gt;
        } catch (InvalidKeyException ike) {&lt;br /&gt;
            throw new RuntimeException(&lt;br /&gt;
                    &amp;quot;Invalid key exception detected. HMac conversion failed.&amp;quot;,&lt;br /&gt;
                    ike);&lt;br /&gt;
        }&lt;br /&gt;
        return result;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns the MD5 digest of the target string. Target is decoded to bytes&lt;br /&gt;
     * using the US-ASCII charset. The returned hexadecimal String always&lt;br /&gt;
     * contains 32 lowercase alphanumeric characters. For example, if target is&lt;br /&gt;
     * &amp;quot;HelloWorld&amp;quot;, this method returns &amp;quot;68e109f0f40ca72a15e05cc22786f8e6&amp;quot;.&lt;br /&gt;
     * &lt;br /&gt;
     * @param target&lt;br /&gt;
     *            The string to encode.&lt;br /&gt;
     * @return The MD5 digest of the target string.&lt;br /&gt;
     */&lt;br /&gt;
    public static String toMd5(String target) {&lt;br /&gt;
        try {&lt;br /&gt;
            return toMd5(target, &amp;quot;US-ASCII&amp;quot;);&lt;br /&gt;
        } catch (UnsupportedEncodingException uee) {&lt;br /&gt;
            // Unlikely, US-ASCII comes with every JVM&lt;br /&gt;
            throw new RuntimeException(&lt;br /&gt;
                    &amp;quot;US-ASCII is an unsupported encoding, unable to compute MD5&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns the MD5 digest of target string. Target is decoded to bytes using&lt;br /&gt;
     * the named charset. The returned hexadecimal String always contains 32&lt;br /&gt;
     * lowercase alphanumeric characters. For example, if target is&lt;br /&gt;
     * &amp;quot;HelloWorld&amp;quot;, this method returns &amp;quot;68e109f0f40ca72a15e05cc22786f8e6&amp;quot;.&lt;br /&gt;
     * &lt;br /&gt;
     * @param target&lt;br /&gt;
     *            The string to encode.&lt;br /&gt;
     * @param charsetName&lt;br /&gt;
     *            The character set.&lt;br /&gt;
     * @return The MD5 digest of the target string.&lt;br /&gt;
     * &lt;br /&gt;
     * @throws UnsupportedEncodingException&lt;br /&gt;
     */&lt;br /&gt;
    public static String toMd5(String target, String charsetName)&lt;br /&gt;
            throws UnsupportedEncodingException {&lt;br /&gt;
        try {&lt;br /&gt;
            final byte[] md5 = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;).digest(&lt;br /&gt;
                    target.getBytes(charsetName));&lt;br /&gt;
            final char[] md5Chars = new char[32];&lt;br /&gt;
            int i = 0;&lt;br /&gt;
            for (final byte b : md5) {&lt;br /&gt;
                md5Chars[i++] = HEXDIGITS[(b &amp;gt;&amp;gt; 4) &amp;amp; 0xF];&lt;br /&gt;
                md5Chars[i++] = HEXDIGITS[b &amp;amp; 0xF];&lt;br /&gt;
            }&lt;br /&gt;
            return new String(md5Chars);&lt;br /&gt;
        } catch (NoSuchAlgorithmException nsae) {&lt;br /&gt;
            throw new RuntimeException(&lt;br /&gt;
                    &amp;quot;No MD5 algorithm, unable to compute MD5&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns the SHA1 digest of the target string. Target is decoded to bytes&lt;br /&gt;
     * using the US-ASCII charset.&lt;br /&gt;
     * &lt;br /&gt;
     * @param target&lt;br /&gt;
     *            The string to encode.&lt;br /&gt;
     * @return The MD5 digest of the target string.&lt;br /&gt;
     */&lt;br /&gt;
    public static String toSha1(String target) {&lt;br /&gt;
        try {&lt;br /&gt;
            return toSha1(target, &amp;quot;US-ASCII&amp;quot;);&lt;br /&gt;
        } catch (UnsupportedEncodingException uee) {&lt;br /&gt;
            // Unlikely, US-ASCII comes with every JVM&lt;br /&gt;
            throw new RuntimeException(&lt;br /&gt;
                    &amp;quot;US-ASCII is an unsupported encoding, unable to compute SHA1&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns the SHA1 digest of target string. Target is decoded to bytes&lt;br /&gt;
     * using the named charset.&lt;br /&gt;
     * &lt;br /&gt;
     * @param target&lt;br /&gt;
     *            The string to encode.&lt;br /&gt;
     * @param charsetName&lt;br /&gt;
     *            The character set.&lt;br /&gt;
     * @return The SHA1 digest of the target string.&lt;br /&gt;
     * &lt;br /&gt;
     * @throws UnsupportedEncodingException&lt;br /&gt;
     */&lt;br /&gt;
    public static String toSha1(String target, String charsetName)&lt;br /&gt;
            throws UnsupportedEncodingException {&lt;br /&gt;
        try {&lt;br /&gt;
            return Base64.encode(MessageDigest.getInstance(&amp;quot;SHA1&amp;quot;).digest(&lt;br /&gt;
                    target.getBytes(charsetName)), false);&lt;br /&gt;
        } catch (NoSuchAlgorithmException nsae) {&lt;br /&gt;
            throw new RuntimeException(&lt;br /&gt;
                    &amp;quot;No SHA1 algorithm, unable to compute SHA1&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
/**&lt;br /&gt;
 * Copyright 2005-2008 Noelios Technologies.&lt;br /&gt;
 * &lt;br /&gt;
 * The contents of this file are subject to the terms of the following open&lt;br /&gt;
 * source licenses: LGPL 3.0 or LGPL 2.1 or CDDL 1.0 (the &amp;quot;Licenses&amp;quot;). You can&lt;br /&gt;
 * select the license that you prefer but you may not use this file except in&lt;br /&gt;
 * compliance with one of these Licenses.&lt;br /&gt;
 * &lt;br /&gt;
 * You can obtain a copy of the LGPL 3.0 license at&lt;br /&gt;
 * http://www.gnu.org/licenses/lgpl-3.0.html&lt;br /&gt;
 * &lt;br /&gt;
 * You can obtain a copy of the LGPL 2.1 license at&lt;br /&gt;
 * http://www.gnu.org/licenses/lgpl-2.1.html&lt;br /&gt;
 * &lt;br /&gt;
 * You can obtain a copy of the CDDL 1.0 license at&lt;br /&gt;
 * http://www.sun.ru/cddl/cddl.html&lt;br /&gt;
 * &lt;br /&gt;
 * See the Licenses for the specific language governing permissions and&lt;br /&gt;
 * limitations under the Licenses.&lt;br /&gt;
 * &lt;br /&gt;
 * Alternatively, you can obtain a royaltee free commercial license with less&lt;br /&gt;
 * limitations, transferable or non-transferable, directly at&lt;br /&gt;
 * http://www.noelios.ru/products/restlet-engine&lt;br /&gt;
 * &lt;br /&gt;
 * Restlet is a registered trademark of Noelios Technologies.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Minimal but fast Base64 codec.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Ray Waldin (ray@waldin.net)&lt;br /&gt;
 */&lt;br /&gt;
 class Base64 {&lt;br /&gt;
    /** alphabet used for encoding bytes into base64 */&lt;br /&gt;
    private static final char[] BASE64_DIGITS = &amp;quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/&amp;quot;&lt;br /&gt;
            .toCharArray();&lt;br /&gt;
    /**&lt;br /&gt;
     * decoding involves replacing each character with the character&amp;quot;s value, or&lt;br /&gt;
     * position, from the above alphabet, and this table makes such lookups&lt;br /&gt;
     * quick and easy. Couldn&amp;quot;t help myself with the corny name :)&lt;br /&gt;
     */&lt;br /&gt;
    private static final byte[] DECODER_RING = new byte[128];&lt;br /&gt;
    static {&lt;br /&gt;
        Arrays.fill(DECODER_RING, (byte) -1);&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        for (final char c : BASE64_DIGITS) {&lt;br /&gt;
            DECODER_RING[c] = (byte) i++;&lt;br /&gt;
        }&lt;br /&gt;
        DECODER_RING[&amp;quot;=&amp;quot;] = 0;&lt;br /&gt;
    }&lt;br /&gt;
    private final static int byteAt(byte[] data, int block, int off) {&lt;br /&gt;
        return unsign(data[(block * 3) + off]);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Decodes a base64 string into bytes. Newline characters found at block&lt;br /&gt;
     * boundaries will be ignored.&lt;br /&gt;
     * &lt;br /&gt;
     * @param encodedString&lt;br /&gt;
     *            The string to decode.&lt;br /&gt;
     * @return The decoded byte array.&lt;br /&gt;
     */&lt;br /&gt;
    public static byte[] decode(String encodedString) {&lt;br /&gt;
        final char[] chars = encodedString.toCharArray();&lt;br /&gt;
        // prepare to ignore newline chars&lt;br /&gt;
        int newlineCount = 0;&lt;br /&gt;
        for (final char c : chars) {&lt;br /&gt;
            switch (c) {&lt;br /&gt;
            case &amp;quot;\r&amp;quot;:&lt;br /&gt;
            case &amp;quot;\n&amp;quot;:&lt;br /&gt;
                newlineCount++;&lt;br /&gt;
                break;&lt;br /&gt;
            default:&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        final int len = chars.length - newlineCount;&lt;br /&gt;
        int numBytes = ((len + 3) / 4) * 3;&lt;br /&gt;
        // fix up length relative to padding&lt;br /&gt;
        if (len &amp;gt; 1) {&lt;br /&gt;
            if (chars[chars.length - 2] == &amp;quot;=&amp;quot;) {&lt;br /&gt;
                numBytes -= 2;&lt;br /&gt;
            } else if (chars[chars.length - 1] == &amp;quot;=&amp;quot;) {&lt;br /&gt;
                numBytes--;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        final byte[] result = new byte[numBytes];&lt;br /&gt;
        int newlineOffset = 0;&lt;br /&gt;
        // decode each block of 4 chars into 3 bytes&lt;br /&gt;
        for (int i = 0; i &amp;lt; (len + 3) / 4; ++i) {&lt;br /&gt;
            int charOffset = newlineOffset + (i * 4);&lt;br /&gt;
            final char c1 = chars[charOffset++];&lt;br /&gt;
            final char c2 = chars[charOffset++];&lt;br /&gt;
            final char c3 = chars[charOffset++];&lt;br /&gt;
            final char c4 = chars[charOffset++];&lt;br /&gt;
            if (!(validChar(c1) &amp;amp;&amp;amp; validChar(c2) &amp;amp;&amp;amp; validChar(c3) &amp;amp;&amp;amp; validChar(c4))) {&lt;br /&gt;
                throw new IllegalArgumentException(&lt;br /&gt;
                        &amp;quot;Invalid Base64 character in block: &amp;quot;&amp;quot; + c1 + c2 + c3&lt;br /&gt;
                                + c4 + &amp;quot;&amp;quot;&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            // pack&lt;br /&gt;
            final int x = DECODER_RING[c1] &amp;lt;&amp;lt; 18 | DECODER_RING[c2] &amp;lt;&amp;lt; 12&lt;br /&gt;
                    | (c3 == &amp;quot;=&amp;quot; ? 0 : DECODER_RING[c3] &amp;lt;&amp;lt; 6)&lt;br /&gt;
                    | (c4 == &amp;quot;=&amp;quot; ? 0 : DECODER_RING[c4]);&lt;br /&gt;
            // unpack&lt;br /&gt;
            int byteOffset = i * 3;&lt;br /&gt;
            result[byteOffset++] = (byte) (x &amp;gt;&amp;gt; 16);&lt;br /&gt;
            if (c3 != &amp;quot;=&amp;quot;) {&lt;br /&gt;
                result[byteOffset++] = (byte) ((x &amp;gt;&amp;gt; 8) &amp;amp; 0xFF);&lt;br /&gt;
                if (c4 != &amp;quot;=&amp;quot;) {&lt;br /&gt;
                    result[byteOffset++] = (byte) (x &amp;amp; 0xFF);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // skip newlines after block&lt;br /&gt;
            outer: while (chars.length &amp;gt; charOffset) {&lt;br /&gt;
                switch (chars[charOffset++]) {&lt;br /&gt;
                case &amp;quot;\r&amp;quot;:&lt;br /&gt;
                case &amp;quot;\n&amp;quot;:&lt;br /&gt;
                    newlineOffset++;&lt;br /&gt;
                    break;&lt;br /&gt;
                default:&lt;br /&gt;
                    break outer;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return result;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Encodes an entire byte array into a Base64 string, with optional newlines&lt;br /&gt;
     * after every 76 characters.&lt;br /&gt;
     * &lt;br /&gt;
     * @param bytes&lt;br /&gt;
     *            The byte array to encode.&lt;br /&gt;
     * @param newlines&lt;br /&gt;
     *            Indicates whether or not newlines are desired.&lt;br /&gt;
     * @return The encoded string.&lt;br /&gt;
     */&lt;br /&gt;
    public static String encode(byte[] bytes, boolean newlines) {&lt;br /&gt;
        return encode(bytes, 0, bytes.length, newlines);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Encodes specified bytes into a Base64 string, with optional newlines&lt;br /&gt;
     * after every 76 characters.&lt;br /&gt;
     * &lt;br /&gt;
     * @param bytes&lt;br /&gt;
     *            The byte array to encode.&lt;br /&gt;
     * @param off&lt;br /&gt;
     *            The starting offset.&lt;br /&gt;
     * @param len&lt;br /&gt;
     *            The number of bytes to encode.&lt;br /&gt;
     * @param newlines&lt;br /&gt;
     *            Indicates whether or not newlines are desired.&lt;br /&gt;
     * &lt;br /&gt;
     * @return The encoded string.&lt;br /&gt;
     */&lt;br /&gt;
    public static String encode(byte[] bytes, int off, int len, boolean newlines) {&lt;br /&gt;
        final char[] output = new char[(((len + 2) / 3) * 4)&lt;br /&gt;
                + (newlines ? len / 43 : 0)];&lt;br /&gt;
        int pos = 0;&lt;br /&gt;
        // encode each block of 3 bytes into 4 chars&lt;br /&gt;
        for (int i = 0; i &amp;lt; (len + 2) / 3; ++i) {&lt;br /&gt;
            int pad = 0;&lt;br /&gt;
            if (len + 1 &amp;lt; (i + 1) * 3) {&lt;br /&gt;
                // two trailing &amp;quot;=&amp;quot;s&lt;br /&gt;
                pad = 2;&lt;br /&gt;
            } else if (len &amp;lt; (i + 1) * 3) {&lt;br /&gt;
                // one trailing &amp;quot;=&amp;quot;&lt;br /&gt;
                pad = 1;&lt;br /&gt;
            }&lt;br /&gt;
            // pack&lt;br /&gt;
            final int x = (byteAt(bytes, i, off) &amp;lt;&amp;lt; 16)&lt;br /&gt;
                    | (pad &amp;gt; 1 ? 0 : (byteAt(bytes, i, off + 1) &amp;lt;&amp;lt; 8))&lt;br /&gt;
                    | (pad &amp;gt; 0 ? 0 : (byteAt(bytes, i, off + 2)));&lt;br /&gt;
            // unpack&lt;br /&gt;
            output[pos++] = BASE64_DIGITS[x &amp;gt;&amp;gt; 18];&lt;br /&gt;
            output[pos++] = BASE64_DIGITS[(x &amp;gt;&amp;gt; 12) &amp;amp; 0x3F];&lt;br /&gt;
            output[pos++] = pad &amp;gt; 1 ? &amp;quot;=&amp;quot; : BASE64_DIGITS[(x &amp;gt;&amp;gt; 6) &amp;amp; 0x3F];&lt;br /&gt;
            output[pos++] = pad &amp;gt; 0 ? &amp;quot;=&amp;quot; : BASE64_DIGITS[x &amp;amp; 0x3F];&lt;br /&gt;
            if (newlines &amp;amp;&amp;amp; ((i + 1) % 19 == 0)) {&lt;br /&gt;
                output[pos++] = &amp;quot;\n&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return new String(output, 0, pos);&lt;br /&gt;
    }&lt;br /&gt;
    private final static int unsign(byte b) {&lt;br /&gt;
        return b &amp;lt; 0 ? b + 256 : b;&lt;br /&gt;
    }&lt;br /&gt;
    private final static boolean validChar(char c) {&lt;br /&gt;
        return (c &amp;lt; 128) &amp;amp;&amp;amp; (DECODER_RING[c] != -1);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Use MD5 to encrypt a string ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
&lt;br /&gt;
public class MD5 {&lt;br /&gt;
    private static MessageDigest digester;&lt;br /&gt;
    static {&lt;br /&gt;
        try {&lt;br /&gt;
            digester = MessageDigest.getInstance(&amp;quot;MD5&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        catch (NoSuchAlgorithmException e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public static String crypt(String str) {&lt;br /&gt;
        if (str == null || str.length() == 0) {&lt;br /&gt;
            throw new IllegalArgumentException(&amp;quot;String to encript cannot be null or zero length&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        digester.update(str.getBytes());&lt;br /&gt;
        byte[] hash = digester.digest();&lt;br /&gt;
        StringBuffer hexString = new StringBuffer();&lt;br /&gt;
        for (int i = 0; i &amp;lt; hash.length; i++) {&lt;br /&gt;
            if ((0xff &amp;amp; hash[i]) &amp;lt; 0x10) {&lt;br /&gt;
                hexString.append(&amp;quot;0&amp;quot; + Integer.toHexString((0xFF &amp;amp; hash[i])));&lt;br /&gt;
            }&lt;br /&gt;
            else {&lt;br /&gt;
                hexString.append(Integer.toHexString(0xFF &amp;amp; hash[i]));&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return hexString.toString();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>