core.crypto
Class Asymmetric

java.lang.Object
  extended by core.crypto.Asymmetric

public class Asymmetric
extends Object

A static class providing all asymmetric cipher operations

  Copyright (c) 2006 Sebastian Erdweg
  Copyright (c) 2006 Dominik Schulz
  Copyright (c) 2006 Florian Lindner
  Copyright (c) 2006 Betim Berjani
  
  This file is part of FlexiCrypt.

  FlexiCrypt is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  FlexiCrypt is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with FlexiCrypt; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  

Author:
Dominik, Sebastian

Field Summary
static String CERT_END_TAG
           
static String CERT_START_TAG
           
static String MODE_PADDING
           
 
Method Summary
static byte[] decrypt(byte[] in, PrivateKey privateKey, int buffersize)
           
static void decrypt(File inputFile, File outputFile, PrivateKey privateKey, int buffersize)
           
static void decrypt(InputStream fis, OutputStream fos, PrivateKey privateKey, int buffersize)
           
static String decrypt(String in, PrivateKey privateKey, int buffersize)
           
static byte[] encrypt(byte[] in, PublicKey publicKey, int buffersize)
           
static void encrypt(File inputFile, File outputFile, PublicKey publicKey, int buffersize)
           
static void encrypt(InputStream fis, OutputStream fos, PublicKey publicKey, int buffersize)
           
static String encrypt(String in, PublicKey publicKey, int buffersize)
           
static KeyPair getNewKeyPair(String algorithm, int keysize)
          This Method generats a new KeyPair
static KeyStore.PrivateKeyEntry getNewPrivateKeyEntry(String asymAlgo, String signAlgo, int keysize, Calendar notBefore, Calendar notAfter, int usage, boolean isUsageCritical, int extendedUsage, boolean isExtendedUsageCritical, boolean isCA, boolean isCACritical, String commonName, String country, String email, String locationCity, String organization, String organizationUnit)
          erzeugt einen privatekeyentry unter angabe aller details
static KeyStore.PrivateKeyEntry getNewPrivateKeyEntry(String asymAlgo, String signAlgo, int keysize, Principal principal, String email, Calendar notBefore, Calendar notAfter, int usage, boolean isUsageCritical, int extendedUsage, boolean isExtendedUsageCritical, boolean isCA, boolean isCACritical)
          Constructs a private key entry with a self-signed cert.
static KeyStore.PrivateKeyEntry getNewPrivateKeyEntry(String asymAlgo, String signAlgo, int keysize, Principal principal, String email, Calendar notBefore, Calendar notAfter, int usage, boolean isUsageCritical, int extendedUsage, boolean isExtendedUsageCritical, boolean isCA, boolean isCACritical, PrivateKey signWith, X509Certificate signersCert)
           
static HashMap<String,Set<Integer>> getValidServices()
          Creates a set of valid asymmetric algorithms
static boolean isValidKeySize(String algorithm, int keysize)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CERT_START_TAG

public static final String CERT_START_TAG
See Also:
Constant Field Values

CERT_END_TAG

public static final String CERT_END_TAG
See Also:
Constant Field Values

MODE_PADDING

public static final String MODE_PADDING
See Also:
Constant Field Values
Method Detail

encrypt

public static byte[] encrypt(byte[] in,
                             PublicKey publicKey,
                             int buffersize)
                      throws InvalidKeyException,
                             NoSuchAlgorithmException,
                             NoSuchPaddingException,
                             IOException,
                             InterruptedException,
                             IllegalBlockSizeException,
                             BadPaddingException
Parameters:
in -
publicKey -
buffersize -
Returns:
Throws:
InvalidKeyException
NoSuchAlgorithmException
NoSuchPaddingException
IOException
InterruptedException
BadPaddingException
IllegalBlockSizeException

encrypt

public static String encrypt(String in,
                             PublicKey publicKey,
                             int buffersize)
                      throws InvalidKeyException,
                             NoSuchAlgorithmException,
                             NoSuchPaddingException,
                             IOException,
                             InterruptedException,
                             IllegalBlockSizeException,
                             BadPaddingException
Parameters:
in -
publicKey -
buffersize -
Returns:
Throws:
InvalidKeyException
NoSuchAlgorithmException
NoSuchPaddingException
IOException
InterruptedException
BadPaddingException
IllegalBlockSizeException

encrypt

public static void encrypt(File inputFile,
                           File outputFile,
                           PublicKey publicKey,
                           int buffersize)
                    throws FileNotFoundException,
                           NoSuchPaddingException,
                           NoSuchAlgorithmException,
                           InvalidKeyException,
                           IOException,
                           InterruptedException,
                           IllegalBlockSizeException,
                           BadPaddingException
Parameters:
inputFile -
outputFile -
publicKey -
buffersize -
Throws:
FileNotFoundException
NoSuchPaddingException
NoSuchAlgorithmException
InvalidKeyException
IOException
InterruptedException
BadPaddingException
IllegalBlockSizeException

encrypt

public static void encrypt(InputStream fis,
                           OutputStream fos,
                           PublicKey publicKey,
                           int buffersize)
                    throws NoSuchAlgorithmException,
                           NoSuchPaddingException,
                           InvalidKeyException,
                           IOException,
                           InterruptedException,
                           IllegalBlockSizeException,
                           BadPaddingException
Parameters:
fis -
fos -
publicKey -
buffersize -
Throws:
NoSuchAlgorithmException
NoSuchPaddingException
InvalidKeyException
IOException
InterruptedException
BadPaddingException
IllegalBlockSizeException

decrypt

public static byte[] decrypt(byte[] in,
                             PrivateKey privateKey,
                             int buffersize)
                      throws InvalidKeyException,
                             NoSuchAlgorithmException,
                             NoSuchPaddingException,
                             IOException,
                             InterruptedException
Parameters:
in -
privateKey -
buffersize -
Returns:
Throws:
InvalidKeyException
NoSuchAlgorithmException
NoSuchPaddingException
IOException
InterruptedException

decrypt

public static String decrypt(String in,
                             PrivateKey privateKey,
                             int buffersize)
                      throws InvalidKeyException,
                             NoSuchAlgorithmException,
                             NoSuchPaddingException,
                             IOException,
                             InterruptedException
Parameters:
in -
privateKey -
buffersize -
Returns:
Throws:
InvalidKeyException
NoSuchAlgorithmException
NoSuchPaddingException
IOException
InterruptedException

decrypt

public static void decrypt(File inputFile,
                           File outputFile,
                           PrivateKey privateKey,
                           int buffersize)
                    throws FileNotFoundException,
                           NoSuchPaddingException,
                           NoSuchAlgorithmException,
                           InvalidKeyException,
                           IOException,
                           InterruptedException
Parameters:
inputFile -
outputFile -
privateKey -
buffersize -
Throws:
FileNotFoundException
NoSuchPaddingException
NoSuchAlgorithmException
InvalidKeyException
IOException
InterruptedException

decrypt

public static void decrypt(InputStream fis,
                           OutputStream fos,
                           PrivateKey privateKey,
                           int buffersize)
                    throws NoSuchAlgorithmException,
                           NoSuchPaddingException,
                           InvalidKeyException,
                           IOException,
                           InterruptedException
Parameters:
fis -
fos -
privateKey -
buffersize -
Throws:
NoSuchAlgorithmException
NoSuchPaddingException
InvalidKeyException
IOException
InterruptedException

getNewPrivateKeyEntry

public static KeyStore.PrivateKeyEntry getNewPrivateKeyEntry(String asymAlgo,
                                                             String signAlgo,
                                                             int keysize,
                                                             Principal principal,
                                                             String email,
                                                             Calendar notBefore,
                                                             Calendar notAfter,
                                                             int usage,
                                                             boolean isUsageCritical,
                                                             int extendedUsage,
                                                             boolean isExtendedUsageCritical,
                                                             boolean isCA,
                                                             boolean isCACritical)
                                                      throws NoSuchAlgorithmException,
                                                             Exception
Constructs a private key entry with a self-signed cert.

Parameters:
asymAlgo -
keysize -
principal -
notBefore -
notAfter -
usage -
Returns:
Throws:
NoSuchAlgorithmException
Exception

getNewPrivateKeyEntry

public static KeyStore.PrivateKeyEntry getNewPrivateKeyEntry(String asymAlgo,
                                                             String signAlgo,
                                                             int keysize,
                                                             Principal principal,
                                                             String email,
                                                             Calendar notBefore,
                                                             Calendar notAfter,
                                                             int usage,
                                                             boolean isUsageCritical,
                                                             int extendedUsage,
                                                             boolean isExtendedUsageCritical,
                                                             boolean isCA,
                                                             boolean isCACritical,
                                                             PrivateKey signWith,
                                                             X509Certificate signersCert)
                                                      throws NoSuchAlgorithmException,
                                                             Exception
Throws:
NoSuchAlgorithmException
Exception

getNewPrivateKeyEntry

public static KeyStore.PrivateKeyEntry getNewPrivateKeyEntry(String asymAlgo,
                                                             String signAlgo,
                                                             int keysize,
                                                             Calendar notBefore,
                                                             Calendar notAfter,
                                                             int usage,
                                                             boolean isUsageCritical,
                                                             int extendedUsage,
                                                             boolean isExtendedUsageCritical,
                                                             boolean isCA,
                                                             boolean isCACritical,
                                                             String commonName,
                                                             String country,
                                                             String email,
                                                             String locationCity,
                                                             String organization,
                                                             String organizationUnit)
                                                      throws NoSuchAlgorithmException,
                                                             Exception
erzeugt einen privatekeyentry unter angabe aller details

Parameters:
asymAlgo -
keysize -
notBefore -
notAfter -
usage -
commonName -
country -
email -
locationCity -
organization -
organizationUnit -
Returns:
Throws:
NoSuchAlgorithmException
Exception

getNewKeyPair

public static KeyPair getNewKeyPair(String algorithm,
                                    int keysize)
                             throws NoSuchAlgorithmException
This Method generats a new KeyPair

Parameters:
algorithm -
keysize -
Returns:
Throws:
NoSuchAlgorithmException

isValidKeySize

public static boolean isValidKeySize(String algorithm,
                                     int keysize)
                              throws NoSuchAlgorithmException
Parameters:
algorithm -
keysize -
Returns:
true if this algorithm with this keysize could be generated
Throws:
NoSuchAlgorithmException - if this algorithm keysize combination is not possible

getValidServices

public static HashMap<String,Set<Integer>> getValidServices()
Creates a set of valid asymmetric algorithms

Returns:
a set of valid asymmetric algorithms