00001 using System; 00002 00003 namespace Tamir.SharpSsh.jsch.jce 00004 { 00005 /* -*-mode:java; c-basic-offset:2; -*- */ 00006 /* 00007 Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved. 00008 00009 Redistribution and use in source and binary forms, with or without 00010 modification, are permitted provided that the following conditions are met: 00011 00012 1. Redistributions of source code must retain the above copyright notice, 00013 this list of conditions and the following disclaimer. 00014 00015 2. Redistributions in binary form must reproduce the above copyright 00016 notice, this list of conditions and the following disclaimer in 00017 the documentation and/or other materials provided with the distribution. 00018 00019 3. The names of the authors may not be used to endorse or promote products 00020 derived from this software without specific prior written permission. 00021 00022 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 00023 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00024 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 00025 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00027 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00028 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00031 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 */ 00033 00034 public class SHA1 : Tamir.SharpSsh.jsch.HASH{ 00035 //MessageDigest md; 00036 internal System.Security.Cryptography.SHA1CryptoServiceProvider md; 00037 private System.Security.Cryptography.CryptoStream cs; 00038 00039 public override int getBlockSize(){return 20;} 00040 public override void init(){ 00041 try 00042 { 00043 //md=MessageDigest.getInstance("SHA-1"); 00044 md=new System.Security.Cryptography.SHA1CryptoServiceProvider(); 00045 cs = new System.Security.Cryptography.CryptoStream( System.IO.Stream.Null, md, System.Security.Cryptography.CryptoStreamMode.Write); 00046 } 00047 catch(Exception e){ 00048 Console.WriteLine(e); 00049 } 00050 } 00051 public override void update(byte[] foo, int start, int len){ 00052 //md.update(foo, start, len); 00053 cs.Write(foo, start, len); 00054 } 00055 public override byte[] digest() { 00056 //return md.digest(); 00057 cs.Close(); 00058 byte[] result = md.Hash; 00059 md.Clear(); 00060 init(); //Reinitiazing hash objects 00061 00062 return result; 00063 } 00064 } 00065 00066 }
1.5.9