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

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Security/SHA_Secure_Hash_Algorithm&amp;diff=4368&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Security/SHA_Secure_Hash_Algorithm&amp;diff=4368&amp;oldid=prev"/>
				<updated>2010-06-01T05:01:59Z</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;Версия 05:01, 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://jexp.ru/index.php?title=Java_Tutorial/Security/SHA_Secure_Hash_Algorithm&amp;diff=4367&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Security/SHA_Secure_Hash_Algorithm&amp;diff=4367&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</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;==  An alternate SHA Interleave algorithm as implemented in the SRP distribution ==&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;
 * JBoss, Home of Professional Open Source.&lt;br /&gt;
 * Copyright 2008, Red Hat Middleware LLC, and individual contributors&lt;br /&gt;
 * as indicated by the @author tags. See the copyright.txt file in the&lt;br /&gt;
 * distribution for a full listing of individual contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it&lt;br /&gt;
 * under the terms of the GNU Lesser General Public License as&lt;br /&gt;
 * published by the Free Software Foundation; either version 2.1 of&lt;br /&gt;
 * the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This software 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 GNU&lt;br /&gt;
 * Lesser General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this software; if not, write to the Free&lt;br /&gt;
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA&lt;br /&gt;
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.ByteArrayOutputStream;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.MessageDigestSpi;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.ProviderException; &lt;br /&gt;
/** An alternate SHA Interleave algorithm as implemented in the SRP&lt;br /&gt;
 distribution. This version reverses the even and odd byte streams before&lt;br /&gt;
 performing the SHA digest.&lt;br /&gt;
 This product includes software developed by Tom Wu and Eugene&lt;br /&gt;
 Jhong for the SRP Distribution (http://srp.stanford.edu/srp/).&lt;br /&gt;
@author Scott.Stark@jboss.org&lt;br /&gt;
@version $Revision: 85945 $&lt;br /&gt;
*/&lt;br /&gt;
public class SHAReverseInterleave extends MessageDigestSpi&lt;br /&gt;
{&lt;br /&gt;
   private static final int SHA_HASH_LEN = 20;&lt;br /&gt;
   private ByteArrayOutputStream evenBytes;&lt;br /&gt;
   private ByteArrayOutputStream oddBytes;&lt;br /&gt;
   private int count;&lt;br /&gt;
   private boolean skipLeadingZeros;&lt;br /&gt;
   private MessageDigest sha;&lt;br /&gt;
   /** Creates a new instance of SHAReverseInterleave&lt;br /&gt;
    @exception ProviderException thrown if MessageDigest.getInstance(&amp;quot;SHA&amp;quot;)&lt;br /&gt;
    throws a NoSuchAlgorithmException.&lt;br /&gt;
    */&lt;br /&gt;
   public SHAReverseInterleave()&lt;br /&gt;
   {&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
         sha = MessageDigest.getInstance(&amp;quot;SHA&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      catch(NoSuchAlgorithmException e)&lt;br /&gt;
      {&lt;br /&gt;
         throw new ProviderException(&amp;quot;Failed to obtain SHA MessageDigest&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      evenBytes = new ByteArrayOutputStream();&lt;br /&gt;
      oddBytes = new ByteArrayOutputStream();&lt;br /&gt;
      engineReset();&lt;br /&gt;
   }&lt;br /&gt;
   protected int engineGetDigestLength()&lt;br /&gt;
   {&lt;br /&gt;
      return 2 * SHA_HASH_LEN;&lt;br /&gt;
   }&lt;br /&gt;
   /**&lt;br /&gt;
    * Completes the digest computation by performing final&lt;br /&gt;
    * operations such as padding. Once &amp;lt;code&amp;gt;engineDigest&amp;lt;/code&amp;gt; has&lt;br /&gt;
    * been called, the engine should be reset (see&lt;br /&gt;
    * {@link #engineReset() engineReset}).&lt;br /&gt;
    * Resetting is the responsibility of the&lt;br /&gt;
    * engine implementor.&lt;br /&gt;
    *&lt;br /&gt;
    * @return the array of bytes for the resulting digest value.&lt;br /&gt;
    */&lt;br /&gt;
   protected byte[] engineDigest()&lt;br /&gt;
   {&lt;br /&gt;
      byte[] E = evenBytes.toByteArray();&lt;br /&gt;
      // If the count is odd, drop the first byte&lt;br /&gt;
      int length = E.length;&lt;br /&gt;
      if( count % 2 == 1 )&lt;br /&gt;
         length --;&lt;br /&gt;
      // Reverse the order of the even bytes&lt;br /&gt;
      byte[] tmp = new byte[length];&lt;br /&gt;
      for(int i = 0; i &amp;lt; length; i ++)&lt;br /&gt;
      {&lt;br /&gt;
         tmp[i] = E[E.length - i - 1];&lt;br /&gt;
         System.out.println(&amp;quot;E[&amp;quot;+i+&amp;quot;] = &amp;quot;+tmp[i]);&lt;br /&gt;
      }&lt;br /&gt;
      E = tmp;&lt;br /&gt;
      byte[] G = sha.digest(E);&lt;br /&gt;
      byte[] F = oddBytes.toByteArray();&lt;br /&gt;
      // Reverse the order of the even bytes&lt;br /&gt;
      tmp = new byte[F.length];&lt;br /&gt;
      for(int i = 0; i &amp;lt; F.length; i ++)&lt;br /&gt;
      {&lt;br /&gt;
         tmp[i] = F[F.length - i - 1];&lt;br /&gt;
         System.out.println(&amp;quot;F[&amp;quot;+i+&amp;quot;] = &amp;quot;+tmp[i]);&lt;br /&gt;
      }&lt;br /&gt;
      F = tmp;&lt;br /&gt;
      sha.reset();&lt;br /&gt;
      byte[] H = sha.digest(F);&lt;br /&gt;
      length = G.length + H.length;&lt;br /&gt;
      byte[] digest = new byte[length];&lt;br /&gt;
      for(int i = 0; i &amp;lt; G.length; ++i)&lt;br /&gt;
         digest[2 * i] = G[i];&lt;br /&gt;
      for(int i = 0; i &amp;lt; H.length; ++i)&lt;br /&gt;
         digest[2 * i + 1] = H[i];&lt;br /&gt;
      engineReset();&lt;br /&gt;
      return digest;&lt;br /&gt;
   }&lt;br /&gt;
   /**&lt;br /&gt;
    * Resets the digest for further use.&lt;br /&gt;
    */&lt;br /&gt;
   protected void engineReset()&lt;br /&gt;
   {&lt;br /&gt;
      skipLeadingZeros = true;&lt;br /&gt;
      count = 0;&lt;br /&gt;
      evenBytes.reset();&lt;br /&gt;
      oddBytes.reset();&lt;br /&gt;
      sha.reset();&lt;br /&gt;
   }&lt;br /&gt;
   /**&lt;br /&gt;
    * Updates the digest using the specified byte.&lt;br /&gt;
    *&lt;br /&gt;
    * @param input the byte to use for the update.&lt;br /&gt;
    */&lt;br /&gt;
   protected void engineUpdate(byte input)&lt;br /&gt;
   {&lt;br /&gt;
      if( skipLeadingZeros == true &amp;amp;&amp;amp; input == 0 )&lt;br /&gt;
         return;&lt;br /&gt;
      skipLeadingZeros = false;&lt;br /&gt;
      if( count % 2 == 0 )&lt;br /&gt;
         evenBytes.write(input);&lt;br /&gt;
      else&lt;br /&gt;
         oddBytes.write(input);&lt;br /&gt;
      count ++;&lt;br /&gt;
   }&lt;br /&gt;
   /**&lt;br /&gt;
    * Updates the digest using the specified array of bytes,&lt;br /&gt;
    * starting at the specified offset.&lt;br /&gt;
    *&lt;br /&gt;
    * @param input the array of bytes to use for the update.&lt;br /&gt;
    * @param offset the offset to start from in the array of bytes.&lt;br /&gt;
    * @param len the input of bytes to use, starting at&lt;br /&gt;
    * &amp;lt;code&amp;gt;offset&amp;lt;/code&amp;gt;.&lt;br /&gt;
    */&lt;br /&gt;
   protected void engineUpdate(byte[] input, int offset, int len)&lt;br /&gt;
   {&lt;br /&gt;
      for(int i = offset; i &amp;lt; offset+len; i ++)&lt;br /&gt;
         engineUpdate(input[i]);&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;
==  Receive Self Mac ==&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;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.ObjectInputStream;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) throws Exception {&lt;br /&gt;
    FileInputStream fis = new FileInputStream(&amp;quot;test&amp;quot;);&lt;br /&gt;
    ObjectInputStream ois = new ObjectInputStream(fis);&lt;br /&gt;
    Object o = ois.readObject();&lt;br /&gt;
    if (!(o instanceof String)) {&lt;br /&gt;
      System.out.println(&amp;quot;Unexpected data in file&amp;quot;);&lt;br /&gt;
      System.exit(-1);&lt;br /&gt;
    }&lt;br /&gt;
    String data = (String) o;&lt;br /&gt;
    System.out.println(&amp;quot;Got message &amp;quot; + data);&lt;br /&gt;
    o = ois.readObject();&lt;br /&gt;
    if (!(o instanceof byte[])) {&lt;br /&gt;
      System.out.println(&amp;quot;Unexpected data in file&amp;quot;);&lt;br /&gt;
      System.exit(-1);&lt;br /&gt;
    }&lt;br /&gt;
    byte origDigest[] = (byte[]) o;&lt;br /&gt;
    byte pass[] = &amp;quot;aaa&amp;quot;.getBytes();&lt;br /&gt;
    byte buf[] = data.getBytes();&lt;br /&gt;
    MessageDigest md = MessageDigest.getInstance(&amp;quot;SHA&amp;quot;);&lt;br /&gt;
    md.update(pass);&lt;br /&gt;
    md.update(buf);&lt;br /&gt;
    byte digest1[] = md.digest();&lt;br /&gt;
    md.update(pass);&lt;br /&gt;
    md.update(digest1);&lt;br /&gt;
    System.out.println(MessageDigest.isEqual(md.digest(), origDigest));&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;
==  Save SHA Message ==&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;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.ObjectOutputStream;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) throws Exception {&lt;br /&gt;
    FileOutputStream fos = new FileOutputStream(&amp;quot;test&amp;quot;);&lt;br /&gt;
    MessageDigest md = MessageDigest.getInstance(&amp;quot;SHA&amp;quot;);&lt;br /&gt;
    ObjectOutputStream oos = new ObjectOutputStream(fos);&lt;br /&gt;
    String data = &amp;quot;thee&amp;quot;;&lt;br /&gt;
    byte buf[] = data.getBytes();&lt;br /&gt;
    md.update(buf);&lt;br /&gt;
    oos.writeObject(data);&lt;br /&gt;
    oos.writeObject(md.digest());&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;
==  SHA MessageDigest ==&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;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.ObjectInputStream;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) throws Exception {&lt;br /&gt;
    FileInputStream fis = new FileInputStream(&amp;quot;test&amp;quot;);&lt;br /&gt;
    ObjectInputStream ois = new ObjectInputStream(fis);&lt;br /&gt;
    Object o = ois.readObject();&lt;br /&gt;
    if (!(o instanceof String)) {&lt;br /&gt;
      System.out.println(&amp;quot;Unexpected data in file&amp;quot;);&lt;br /&gt;
      System.exit(-1);&lt;br /&gt;
    }&lt;br /&gt;
    String data = (String) o;&lt;br /&gt;
    System.out.println(&amp;quot;Got message &amp;quot; + data);&lt;br /&gt;
    o = ois.readObject();&lt;br /&gt;
    if (!(o instanceof byte[])) {&lt;br /&gt;
      System.out.println(&amp;quot;Unexpected data in file&amp;quot;);&lt;br /&gt;
      System.exit(-1);&lt;br /&gt;
    }&lt;br /&gt;
    byte origDigest[] = (byte[]) o;&lt;br /&gt;
    MessageDigest md = MessageDigest.getInstance(&amp;quot;SHA&amp;quot;);&lt;br /&gt;
    md.update(data.getBytes());&lt;br /&gt;
    if (MessageDigest.isEqual(md.digest(), origDigest))&lt;br /&gt;
      System.out.println(&amp;quot;Message is valid&amp;quot;);&lt;br /&gt;
    else&lt;br /&gt;
      System.out.println(&amp;quot;Message was corrupted&amp;quot;);&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>