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 Random : Tamir.SharpSsh.jsch.Random 00035 { 00036 private byte[] tmp=new byte[16]; 00037 //private SecureRandom random; 00038 private System.Security.Cryptography.RNGCryptoServiceProvider rand; 00039 public Random() 00040 { 00041 // random=null; 00042 // random = new SecureRandom(); 00043 // 00044 // try{ random=SecureRandom.getInstance("SHA1PRNG"); } 00045 // catch(java.security.NoSuchAlgorithmException e){ 00046 // // System.out.println(e); 00047 // 00048 // // The following code is for IBM's JCE 00049 // try{ random=SecureRandom.getInstance("IBMSecureRandom"); } 00050 // catch(java.security.NoSuchAlgorithmException ee){ 00051 // System.out.println(ee); 00052 // } 00053 // } 00054 rand = new System.Security.Cryptography.RNGCryptoServiceProvider(); 00055 } 00056 static int times = 0; 00057 public void fill(byte[] foo, int start, int len) 00058 { 00059 try 00060 { 00061 if(len>tmp.Length){ tmp=new byte[len]; } 00062 //random.nextBytes(tmp); 00063 rand.GetBytes(tmp); 00064 Array.Copy(tmp, 0, foo, start, len); 00065 } 00066 catch(Exception e) 00067 { 00068 times++; 00069 Console.WriteLine(times+") Array.Copy(tmp={0}, 0, foo={1}, {2}, {3}", tmp.Length, foo.Length, start, len); 00070 //Console.WriteLine(e.StackTrace); 00071 } 00072 } 00073 } 00074 00075 }
1.5.9