KeyPairGenRSA.java

Go to the documentation of this file.
00001 /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
00002 /*
00003 Copyright (c) 2002-2011 ymnk, JCraft,Inc. All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007 
00008   1. Redistributions of source code must retain the above copyright notice,
00009      this list of conditions and the following disclaimer.
00010 
00011   2. Redistributions in binary form must reproduce the above copyright 
00012      notice, this list of conditions and the following disclaimer in 
00013      the documentation and/or other materials provided with the distribution.
00014 
00015   3. The names of the authors may not be used to endorse or promote products
00016      derived from this software without specific prior written permission.
00017 
00018 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
00019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
00021 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
00022 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00023 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00025 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00026 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00027 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 */
00029 
00030 package com.jcraft.jsch.jce;
00031 
00032 import java.security.*;
00033 import java.security.interfaces.*;
00034 
00035 public class KeyPairGenRSA implements com.jcraft.jsch.KeyPairGenRSA{
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   public void init(int key_size) throws Exception{
00047     KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
00048     keyGen.initialize(key_size, new SecureRandom());
00049     KeyPair pair = keyGen.generateKeyPair();
00050 
00051     PublicKey pubKey=pair.getPublic();
00052     PrivateKey prvKey=pair.getPrivate();
00053 
00054     d=((RSAPrivateKey)prvKey).getPrivateExponent().toByteArray();
00055     e=((RSAPublicKey)pubKey).getPublicExponent().toByteArray();
00056     n=((RSAPrivateKey)prvKey).getModulus().toByteArray();
00057 
00058     c=((RSAPrivateCrtKey)prvKey).getCrtCoefficient().toByteArray();
00059     ep=((RSAPrivateCrtKey)prvKey).getPrimeExponentP().toByteArray();
00060     eq=((RSAPrivateCrtKey)prvKey).getPrimeExponentQ().toByteArray();
00061     p=((RSAPrivateCrtKey)prvKey).getPrimeP().toByteArray();
00062     q=((RSAPrivateCrtKey)prvKey).getPrimeQ().toByteArray();
00063   }
00064   public byte[] getD(){return d;}
00065   public byte[] getE(){return e;}
00066   public byte[] getN(){return n;}
00067   public byte[] getC(){return c;}
00068   public byte[] getEP(){return ep;}
00069   public byte[] getEQ(){return eq;}
00070   public byte[] getP(){return p;}
00071   public byte[] getQ(){return q;}
00072 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1