com.vodafone360.people.engine.login
Class RSAEncryptionUtils

java.lang.Object
  extended by com.vodafone360.people.engine.login.RSAEncryptionUtils

public class RSAEncryptionUtils
extends java.lang.Object

Utility class for encrypting/decrypting login and registration user credentials.


Field Summary
private static byte[] DEFAULT_PUBKEY_EXPONENTIAL
          Exponential part of the public key.
private static byte[] DEFAULT_PUBKEY_MODULO
          Default public key which can be used to encrypt data.
private static int ROUND_UP_VALUE
          Ensures data length is always a multiple of 16 (by rounding up if necessary).
 
Constructor Summary
RSAEncryptionUtils()
           
 
Method Summary
static void copyDefaultPublicKey(PublicKeyDetails key)
          Copies the default key into the given parameter.
protected static byte[] encryptRSA(RSAKeyParameters pubKey, java.lang.String data)
          Encrypts bytes with the given RSA Public Key.
protected static RSAKeyParameters getDefaultPublicKey()
          Fetches the default public key.
protected static RSAKeyParameters getRSAPubKey(byte[] mod, byte[] exp)
          Composes a RSA Public Key from its components.
private static int roundUp(int v, int t)
          Return the value of v rounded up to a multiple of t
private static byte[] rsa(boolean encrypt, RSAKeyParameters key, byte[] data)
          Encrypts or Decrypts bytes with the given RSA Public or Private Key.
private static byte[] trimZeros(byte[] data)
          Removes all the zeros from the end of the given array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PUBKEY_MODULO

private static final byte[] DEFAULT_PUBKEY_MODULO
Default public key which can be used to encrypt data. The server has the suitable private key for decrypting the data. This is the modulo part.


DEFAULT_PUBKEY_EXPONENTIAL

private static final byte[] DEFAULT_PUBKEY_EXPONENTIAL
Exponential part of the public key.


ROUND_UP_VALUE

private static final int ROUND_UP_VALUE
Ensures data length is always a multiple of 16 (by rounding up if necessary).

See Also:
Constant Field Values
Constructor Detail

RSAEncryptionUtils

public RSAEncryptionUtils()
Method Detail

getDefaultPublicKey

protected static RSAKeyParameters getDefaultPublicKey()
Fetches the default public key.

Returns:
Public key

copyDefaultPublicKey

public static void copyDefaultPublicKey(PublicKeyDetails key)
Copies the default key into the given parameter.

Parameters:
key - Where the key should be copied.

getRSAPubKey

protected static RSAKeyParameters getRSAPubKey(byte[] mod,
                                               byte[] exp)
Composes a RSA Public Key from its components.

Parameters:
mod - the RSA modulo.
exp - the RSA exponent.
Returns:
the RSA public key.

encryptRSA

protected static byte[] encryptRSA(RSAKeyParameters pubKey,
                                   java.lang.String data)
                            throws InvalidCipherTextException
Encrypts bytes with the given RSA Public Key.

Parameters:
pubKey - the RSA Public Key.
data - the data to encrypt.
Returns:
the encrypted data.
Throws:
java.security.InvalidParameterException
InvalidCipherTextException

rsa

private static byte[] rsa(boolean encrypt,
                          RSAKeyParameters key,
                          byte[] data)
                   throws InvalidCipherTextException
Encrypts or Decrypts bytes with the given RSA Public or Private Key.

Parameters:
encrypt - true for encrypt, false for decrypt.
key - the RSA Public or Private Key.
data - the data to encrypt or decrypt.
Returns:
the encrypted or decrypted data.
Throws:
InvalidCipherTextException

roundUp

private static int roundUp(int v,
                           int t)
Return the value of v rounded up to a multiple of t

Parameters:
v - The value to round up
t - The multiple to use
Returns:
The rounded result

trimZeros

private static byte[] trimZeros(byte[] data)
Removes all the zeros from the end of the given array.

Parameters:
data - Initial array to trim
Returns:
New array which n less elements (where n = number of trailing zeros). If the given array is all zeros then the function will fail and the result will be the initial array (NULL if initial array is NULL)


JavaDoc