core.crypto
Class Symmetric

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

public class Symmetric
extends Object

A static class Providing all symmetric 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 SECRET_KEY_END_TAG
           
static String SECRET_KEY_START_TAG
           
 
Method Summary
static byte[] decrypt(byte[] in, SecretKey secretKey, int buffersize)
           
static void decrypt(File inputFile, File outputFile, SecretKey secretKey, int buffersize)
           
static void decrypt(InputStream fis, OutputStream fos, SecretKey secretKey, int buffersize)
           
static String decrypt(String in, SecretKey secretKey, int buffersize)
           
static byte[] encrypt(byte[] in, SecretKey secretKey, int buffersize)
           
static void encrypt(File inputFile, File outputFile, SecretKey secretKey, int buffersize)
           
static void encrypt(InputStream fis, OutputStream fos, SecretKey secretKey, int buffersize)
           
static String encrypt(String in, SecretKey secretKey, int buffersize)
           
static SecretKey getNewKey(String algorithm, int keySize)
          Erzeugt einen neuen symmetrischen Schl├╝ssel
static SecretKey getNewPBEKey(char[] password)
          Constructs a passphrase based encryption key by computing its hashvalue 5 times with MD5 and then creating an RC6 key out of it.
static HashMap<String,Set<Integer>> getValidServices()
          Creates a set of valid symmetric algorithms
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SECRET_KEY_START_TAG

public static final String SECRET_KEY_START_TAG
See Also:
Constant Field Values

SECRET_KEY_END_TAG

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

decrypt

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

decrypt

public static String decrypt(String in,
                             SecretKey secretKey,
                             int buffersize)
                      throws InvalidKeyException,
                             NoSuchPaddingException,
                             NoSuchAlgorithmException,
                             IOException,
                             InterruptedException
Parameters:
in -
secretKey -
buffersize -
Returns:
the decrypted string
Throws:
InvalidKeyException
NoSuchPaddingException
NoSuchAlgorithmException
IOException
InterruptedException

decrypt

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

decrypt

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

encrypt

public static byte[] encrypt(byte[] in,
                             SecretKey secretKey,
                             int buffersize)
                      throws InvalidKeyException,
                             NoSuchPaddingException,
                             NoSuchAlgorithmException,
                             IOException,
                             InterruptedException
Parameters:
in -
secretKey -
buffersize -
Returns:
the encrypted byte array
Throws:
InvalidKeyException
NoSuchPaddingException
NoSuchAlgorithmException
IOException
InterruptedException

encrypt

public static String encrypt(String in,
                             SecretKey secretKey,
                             int buffersize)
                      throws InvalidKeyException,
                             NoSuchPaddingException,
                             NoSuchAlgorithmException,
                             IOException,
                             InterruptedException
Throws:
InvalidKeyException
NoSuchPaddingException
NoSuchAlgorithmException
IOException
InterruptedException

encrypt

public static void encrypt(File inputFile,
                           File outputFile,
                           SecretKey secretKey,
                           int buffersize)
                    throws FileNotFoundException,
                           NoSuchPaddingException,
                           NoSuchAlgorithmException,
                           InvalidKeyException,
                           IOException,
                           InterruptedException
Parameters:
inputFile -
outputFile -
secretKey -
buffersize -
Throws:
FileNotFoundException
NoSuchPaddingException
NoSuchAlgorithmException
InvalidKeyException
IOException - Encryption using Files
InterruptedException

encrypt

public static void encrypt(InputStream fis,
                           OutputStream fos,
                           SecretKey secretKey,
                           int buffersize)
                    throws NoSuchPaddingException,
                           NoSuchAlgorithmException,
                           InvalidKeyException,
                           IOException,
                           InterruptedException
Parameters:
fis - - The FileInputStream containing the encrypted data
fos - - The FileOutputStrem to write the decrypted data
secretKey - - The secret key (shared secret) used to encrypt the data
buffersize -
Throws:
InterruptedException
BadPaddingException
IllegalBlockSizeException
NoSuchPaddingException
NoSuchAlgorithmException
InvalidKeyException
IOException

getNewKey

public static SecretKey getNewKey(String algorithm,
                                  int keySize)
                           throws NoSuchAlgorithmException
Erzeugt einen neuen symmetrischen Schl├╝ssel

Parameters:
algorithm -
keySize -
Returns:
a new symmetric key with the given keysize and algorithm
Throws:
NoSuchAlgorithmException

getNewPBEKey

public static SecretKey getNewPBEKey(char[] password)
                              throws NoSuchAlgorithmException,
                                     InvalidAlgorithmParameterException,
                                     InterruptedException,
                                     IOException
Constructs a passphrase based encryption key by computing its hashvalue 5 times with MD5 and then creating an RC6 key out of it.

Parameters:
password -
Returns:
a new SecretKey
Throws:
NoSuchAlgorithmException
IOException
InterruptedException
InvalidAlgorithmParameterException

getValidServices

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

Returns:
a set of valid symmetric algorithms