de.unikassel.android.sdcframework.util.facade
Class Encryption

Package class diagram package Encryption
java.lang.Object
  extended by de.unikassel.android.sdcframework.util.facade.Encryption

public final class Encryption
extends Object

Utility class for encryption and checksums.


Field Summary
static String PRIVATE_KEY_FILE
          private key file name
static String PUBLIC_KEY_FILE
          public key file name
private static String RSA_ALGORITHM
          The RSA algorithm description
private static String RSA_ENCRYPTION
          The RSA transformation description for encryption
private static int RSA_KEY_LENGTH
          The RSA key length
 
Constructor Summary
Encryption()
           
 
Method Summary
static KeyPair createRSAKeyPair()
          Method to create an RSA key pair of RSA_KEY_LENGTH bit length and save the key bytes to files.
static boolean decryptRSA(PrivateKey key, File srcFile, File destFile)
          Method for RSA file decryption
static boolean encryptRSA(PublicKey key, File srcFile, File destFile)
          Method for RSA file encryption
static String md5(String text)
          Method to create an MD5 hash for a given string
static PrivateKey readPrivateKeyFromFile(File file)
          Method to read a private key from file
static PublicKey readPublicKeyFromFile(File file)
          Method to read a public key from file
static PublicKey readPublicKeyFromStream(InputStream is)
          Method to read a public key from an input stream
private static byte[] readRSAKeyFromFile(File file)
          Method to store a public or a private RSA key bytes
static byte[] readRSAKeyFromStream(InputStream is)
          Method to store a public or a private RSA key bytes
static void saveRSAKeyToFile(String file, byte[] bytes)
          Method to store a public or a private RSA key bytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRIVATE_KEY_FILE

public static final String PRIVATE_KEY_FILE
private key file name

See Also:
Constant Field Values

PUBLIC_KEY_FILE

public static final String PUBLIC_KEY_FILE
public key file name

See Also:
Constant Field Values

RSA_KEY_LENGTH

private static final int RSA_KEY_LENGTH
The RSA key length

See Also:
Constant Field Values

RSA_ALGORITHM

private static final String RSA_ALGORITHM
The RSA algorithm description

See Also:
Constant Field Values

RSA_ENCRYPTION

private static final String RSA_ENCRYPTION
The RSA transformation description for encryption

See Also:
Constant Field Values
Constructor Detail

Encryption

public Encryption()
Method Detail

md5

public static final String md5(String text)
Method to create an MD5 hash for a given string

Parameters:
text - the string to create MD5 hash for
Returns:
the MD5 hash for the text

encryptRSA

public static final boolean encryptRSA(PublicKey key,
                                       File srcFile,
                                       File destFile)
Method for RSA file encryption

Parameters:
key - the public key to use for encryption
srcFile - the source file to encrypt
destFile - the file to store encrypted data in
Returns:
true if successful, false otherwise

decryptRSA

public static final boolean decryptRSA(PrivateKey key,
                                       File srcFile,
                                       File destFile)
Method for RSA file decryption

Parameters:
key - the private key to use for decryption
srcFile - the source file to decrypt
destFile - the file to store decrypted data in
Returns:
true if successful, false otherwise

createRSAKeyPair

public static final KeyPair createRSAKeyPair()
Method to create an RSA key pair of RSA_KEY_LENGTH bit length and save the key bytes to files.

Returns:
the genrated key pair

saveRSAKeyToFile

public static final void saveRSAKeyToFile(String file,
                                          byte[] bytes)
                                   throws IOException
Method to store a public or a private RSA key bytes

Parameters:
file - the file to save the key into
bytes - the key bytes
Throws:
IOException

readPublicKeyFromFile

public static final PublicKey readPublicKeyFromFile(File file)
Method to read a public key from file

Parameters:
file - the file to read the public key from
Returns:
the public key

readPublicKeyFromStream

public static final PublicKey readPublicKeyFromStream(InputStream is)
Method to read a public key from an input stream

Parameters:
is - the input stream to read from
Returns:
the public key

readPrivateKeyFromFile

public static final PrivateKey readPrivateKeyFromFile(File file)
Method to read a private key from file

Parameters:
file - the file to read the private key from
Returns:
the private key

readRSAKeyFromFile

private static final byte[] readRSAKeyFromFile(File file)
                                        throws IOException
Method to store a public or a private RSA key bytes

Parameters:
file - the file to read the public key from
Returns:
the key bytes
Throws:
IOException

readRSAKeyFromStream

public static final byte[] readRSAKeyFromStream(InputStream is)
                                         throws IOException
Method to store a public or a private RSA key bytes

Parameters:
is - the input stream to read the public key from
Returns:
the key bytes
Throws:
IOException