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 KeyPairGenRSA : Tamir.SharpSsh.jsch.KeyPairGenRSA 00035 { 00036 byte[] d; // private 00037 byte[] e; // public 00038 byte[] n; 00039 00040 byte[] c; // coefficient 00041 byte[] ep; // exponent p 00042 byte[] eq; // exponent q 00043 byte[] p; // prime p 00044 byte[] q; // prime q 00045 00046 System.Security.Cryptography.RSAParameters RSAKeyInfo; 00047 00048 public void init(int key_size) 00049 { 00050 // KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); 00051 // keyGen.initialize(key_size, new SecureRandom()); 00052 // KeyPair pair = keyGen.generateKeyPair(); 00053 // 00054 // PublicKey pubKey=pair.getPublic(); 00055 // PrivateKey prvKey=pair.getPrivate(); 00056 00057 System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(key_size); 00058 RSAKeyInfo = rsa.ExportParameters(true); 00059 00060 // d=((RSAPrivateKey)prvKey).getPrivateExponent().toByteArray(); 00061 // e=((RSAPublicKey)pubKey).getPublicExponent().toByteArray(); 00062 // n=((RSAKey)prvKey).getModulus().toByteArray(); 00063 // 00064 // c=((RSAPrivateCrtKey)prvKey).getCrtCoefficient().toByteArray(); 00065 // ep=((RSAPrivateCrtKey)prvKey).getPrimeExponentP().toByteArray(); 00066 // eq=((RSAPrivateCrtKey)prvKey).getPrimeExponentQ().toByteArray(); 00067 // p=((RSAPrivateCrtKey)prvKey).getPrimeP().toByteArray(); 00068 // q=((RSAPrivateCrtKey)prvKey).getPrimeQ().toByteArray(); 00069 00070 d= RSAKeyInfo.D ; 00071 e=RSAKeyInfo.Exponent ; 00072 n=RSAKeyInfo.Modulus ; 00073 00074 c=RSAKeyInfo.InverseQ ; 00075 ep=RSAKeyInfo.DP ; 00076 eq=RSAKeyInfo.DQ ; 00077 p=RSAKeyInfo.P ; 00078 q=RSAKeyInfo.Q ; 00079 } 00080 public byte[] getD(){return d;} 00081 public byte[] getE(){return e;} 00082 public byte[] getN(){return n;} 00083 public byte[] getC(){return c;} 00084 public byte[] getEP(){return ep;} 00085 public byte[] getEQ(){return eq;} 00086 public byte[] getP(){return p;} 00087 public byte[] getQ(){return q;} 00088 public System.Security.Cryptography.RSAParameters KeyInfo 00089 { 00090 get{return RSAKeyInfo;} 00091 } 00092 } 00093 }
1.5.9