SecurePlayLibray J2SE
v2.1

com.SecurePlay
Class SPUtil

java.lang.Object
  extended bycom.SecurePlay.SPUtil

public class SPUtil
extends java.lang.Object

These are global functions and constants that can be used by various portions of the SecurePlay library. Some methods in this class wrap functions to accomodate between J2me and J2se. NOTE: Some may be simply placeholders for application specific services such as the hash, encryption, and signature functions.

Author:
IT GlobalSecure
See Also:
SecurePlay License Information
 

Field Summary
static java.lang.String intDel
          Delimiter1 = : Used for serializing internal message arrays
static java.lang.String interMessDell
          Delimeter3 = ~ Used for serializing multiple messages
static java.lang.String INTERNAL_COMMS
          Comms internal
static java.lang.String messDel
          Delimiter2 = ; Used for serializing the message
private static java.util.Random ran
          Global static random property that generates random numbers for key creation.
static int SP_ID_SIZE
          This value is used to set the default size of generated IDs - default is 12
static int SP_KEY_SIZE
          This value is used to set game key size.
static java.lang.String SP_TESTSEGMENT
          This Constant is used to generate a Game Segment ID for sample code.
static int SP_UPDATE_INTERVAL
          This parameter is used to force an update check - only necessary for polling communications.
private static SPMap transactionRegistry
          This property holds transaction instances available to this class.
 
Constructor Summary
SPUtil()
          Default Constructor.
 
Method Summary
static java.util.Vector addVectorToVector(java.util.Vector v1, java.util.Vector v2)
          This method adds two vectors together.
static java.lang.String[] ArrayIntersection(java.lang.String[] arr1, java.lang.String[] arr2)
          Cross References two string array and returns the common strings or mathces occured between two arrays.
static boolean arrComp(byte[] b1, byte[] b2)
          This method compares two byte arrays.
static java.lang.Integer[] arrSplice(java.lang.Integer[] iarr, int pos)
          Returns a new array that removes a single element from the input Integer array at a given position
static java.lang.String BinaryToString(byte[] digest)
          This method convets a byte array to a string where each byte is split into two characters providing the hex representation of the byte.
static byte[] ByteArrAddArr(byte[] sa1, byte[] sa2)
          This method add two byte arrays together.
static byte[] ByteArrAddEl(byte[] sa, byte str)
          This function appends a byte element to the end of the byte array.
static byte[] ByteArrGETsubArr(byte[] strArr, int indexStart, int indexEnd)
          This method gets the sub array of a Stirng array.
static java.lang.String[] ByteArrToStringArr(byte[] bt)
          Converts byte array into string array.
static java.lang.String char62circadd(java.lang.String str1, java.lang.String str2)
          This function does a circular, character by character addition mod 62 assuming the strings are "right justified".
static java.lang.String char62circsub(java.lang.String str1, java.lang.String str2)
          This function does a circular, character by character subtraction mod 62 assuming the strings are "right justified" this returns the result as a new string.
static int char62code2num(char c)
          This function takes the character code provided and converts it to a number between 0 and 61
static boolean compareStringArrays(java.lang.String[] str1, java.lang.String[] str2)
          Compares two string arrays if they contain identical items.
static byte[] getHashText(java.lang.String plainText, java.lang.String algorithm)
          This method gets the hashed string
static int getNextRandom()
           
static SPAbstractTransactionInterface getRegisteredTransaction(java.lang.String key)
          This method gets a registered Transaction object from the register list and returns it to the user.
static long getTime()
           
private static SPMap getTransactionRegistry()
          This method returns the transaction registry list.
static int HexStringToInt(java.lang.String str)
           
static java.lang.Integer[] IntArrAddEl(java.lang.Integer[] iarr, int i)
          This function appends a integer element to the end of the integer array.
static java.lang.String INTdelimiter()
          Returns a String delimiter1 Delimiter1 = ":" Used for serializing internal message arrays
static java.lang.String INTMESSdelimiter()
          Returns a String delimiter3 Delimiter3 = "~" Used for serialising multiple messages
static byte[] IntToByte(int i)
          This method converts an integer into a byte array.
static java.lang.String IntToString(int i)
          Integer to String.
static boolean IsArrayIntersectionTrue(java.lang.String[] arr1, java.lang.String[] arr2)
          Cross References two string array and returns number of same strings or mathces occured between two arrays.
static boolean isElementIncluded(java.lang.String elem, java.lang.String[] array)
          This method checks to see if an element is included in a string array.
static boolean isElementIncluded(java.lang.String elem, java.util.Vector array)
          This method checks to see if an element is included in a vector.
static java.lang.String LongToString(long i)
          Long to String.
static java.lang.String MESSdelimiter()
          Returns a String delmiter2 Delimiter2 = ";" Used for serializing the message
static int num2char62code(int x)
          this function takes a numerical value between 0 and 61 and converts it to a character code from 0..9A..Za..z
static boolean registerTransaction(java.lang.String transName, SPAbstractTransactionInterface transInstance)
          This method registers Transaction objects with so that they can be used in this library.
static java.lang.String rippleadd1(java.lang.String inputstring)
          This function adds 1 to the low order character of a string.
static byte[] SPclone(byte[] byteArr)
          This method clones a byte array and makes a copy.
static java.util.Hashtable SPclone(java.util.Hashtable htbl)
          This method wraps the proper clone method of hashtable for ME and SE interoperability.
static java.lang.String[] SPclone(java.lang.String[] strArr)
          This method clones a string array and makes a copy.
static java.lang.String SPgenerateKey(int keySize)
          This function generates a "real" random key that is easily stored in a printable string.
static int SPsmoothValue(int sampleSize, int seed, java.lang.Integer[] keyArray)
          This is a somewhat smooth, keyed, pseudorandom number generator.
static java.lang.String SPtransform(java.lang.String input, java.lang.String gameid)
          This function performs an irreversible transform on an input string to generate an output string.
static java.lang.String[] StringArrAddArr(java.lang.String[] sa1, java.lang.String[] sa2)
          This method add two string arrays together.
static java.lang.String[] StringArrAddEl(java.lang.String[] sa, java.lang.String str)
          This function appends a string element to the end of the String array.
static boolean StringArrContainsEl(java.lang.String[] arr, java.lang.String elem)
          Checks to see if the array contains the specified element.
static java.lang.String[] StringArrGETsubArr(java.lang.String[] strArr, int indexStart, int indexEnd)
          This method gets the sub array of a Stirng array.
static java.lang.String[] StringArrRemoveEl(java.lang.String[] sa, java.lang.String str)
          This function removes a string element from a String array.
static byte[] StringArrToByteArr(java.lang.String[] strarr)
          This method converts a String array to a byte array.
static java.lang.String StringArrToString(java.lang.String[] sa, java.lang.String delim)
          Parces the string array into a string with delimiters separating each array indexes
static java.util.Vector StringArrToVector(java.lang.String[] strArr)
          This method converts a string array to a vector.
static byte[] StringToBinary(java.lang.String str)
          String to binary
static int StringToInt(java.lang.String str)
          String to integer.
static long StringToLong(java.lang.String str)
          String to Long.
static java.lang.String[] StringToStringArr(java.lang.String str, java.lang.String del)
          This method converts a string to a string array using the specified delimiter.
static byte[] subByteArr(byte[] inbArr, int start, int end)
          This method retrieves the specified sub array of a byte array passed in.
static java.lang.Integer toInt(java.lang.String str)
          Converts a string representaion of an integer to Integer class.
static java.lang.String toString(int i)
          Converts an integer to string.
static java.lang.String vectorToString(java.util.Vector v, java.lang.String delim)
          Concatinates the objects in a Vector into a string using a delimiter.
static java.lang.String[] VectorToStringArr(java.util.Vector v)
          This method converts a Vector to a string array.
static java.lang.String[] viewRegisteredTransaction()
          This method allows users to see what transactions have been registered.
static int XreferenceTwoArrays(java.lang.String[] arr1, java.lang.String[] arr2)
          Cross References two string array and returns number of same strings or mathces occured between two arrays.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERNAL_COMMS

public static final java.lang.String INTERNAL_COMMS
Comms internal

See Also:
Constant Field Values

SP_ID_SIZE

public static final int SP_ID_SIZE
This value is used to set the default size of generated IDs - default is 12

See Also:
Constant Field Values

SP_KEY_SIZE

public static final int SP_KEY_SIZE
This value is used to set game key size. Default is 25.

See Also:
Constant Field Values

SP_UPDATE_INTERVAL

public static final int SP_UPDATE_INTERVAL
This parameter is used to force an update check - only necessary for polling communications. Default is 3800.

See Also:
Constant Field Values

SP_TESTSEGMENT

public static java.lang.String SP_TESTSEGMENT
This Constant is used to generate a Game Segment ID for sample code.


intDel

public static final java.lang.String intDel
Delimiter1 = : Used for serializing internal message arrays

See Also:
Constant Field Values

messDel

public static final java.lang.String messDel
Delimiter2 = ; Used for serializing the message

See Also:
Constant Field Values

interMessDell

public static final java.lang.String interMessDell
Delimeter3 = ~ Used for serializing multiple messages

See Also:
Constant Field Values

transactionRegistry

private static SPMap transactionRegistry
This property holds transaction instances available to this class.


ran

private static java.util.Random ran
Global static random property that generates random numbers for key creation.

Constructor Detail

SPUtil

public SPUtil()
Default Constructor.

Method Detail

rippleadd1

public static java.lang.String rippleadd1(java.lang.String inputstring)
This function adds 1 to the low order character of a string. It returns the result as a returned string value the input string is from the range - 0..9A..Za..z.

Parameters:
inputstring - String
Returns:
resultstring - String

char62circadd

public static java.lang.String char62circadd(java.lang.String str1,
                                             java.lang.String str2)
This function does a circular, character by character addition mod 62 assuming the strings are "right justified". This returns the result as a new string.

Parameters:
str1 - String
str2 - String
Returns:
resultstring - String:

char62circsub

public static java.lang.String char62circsub(java.lang.String str1,
                                             java.lang.String str2)
This function does a circular, character by character subtraction mod 62 assuming the strings are "right justified" this returns the result as a new string.

Parameters:
str1 - String
str2 - String
Returns:
resultstring - String

char62code2num

public static int char62code2num(char c)
This function takes the character code provided and converts it to a number between 0 and 61

Parameters:
c - char - a character code
Returns:
x - int - a number between 0 and 61

num2char62code

public static int num2char62code(int x)
this function takes a numerical value between 0 and 61 and converts it to a character code from 0..9A..Za..z

Parameters:
x - int - a number between 0 and 61
Returns:
c - int - a character code

SPsmoothValue

public static int SPsmoothValue(int sampleSize,
                                int seed,
                                java.lang.Integer[] keyArray)
This is a somewhat smooth, keyed, pseudorandom number generator. It generates a result between 0 and SampleSize -1. It uses the seed to generate a range of possible outcomes and it is driven by an array keyArray. THIS FUNCTION SHOULD NOT BE USED FOR PRODUCTION GAMES. CAREFUL SELECTION OF PSEUDO-RANDOM NUMBER GENERATORS IS CRITICAL.

Parameters:
sampleSize - int
seed - int
keyArray - Integer[]
Returns:
Positive - int - pseudorandom number.

INTdelimiter

public static java.lang.String INTdelimiter()
Returns a String delimiter1 Delimiter1 = ":" Used for serializing internal message arrays

Returns:
del - String

MESSdelimiter

public static java.lang.String MESSdelimiter()
Returns a String delmiter2 Delimiter2 = ";" Used for serializing the message

Returns:
del2 - String

INTMESSdelimiter

public static java.lang.String INTMESSdelimiter()
Returns a String delimiter3 Delimiter3 = "~" Used for serialising multiple messages

Returns:
String

vectorToString

public static java.lang.String vectorToString(java.util.Vector v,
                                              java.lang.String delim)
Concatinates the objects in a Vector into a string using a delimiter.

Parameters:
v - Vector - Vector to be converted
delim - String - delimiter to be used

StringArrToString

public static java.lang.String StringArrToString(java.lang.String[] sa,
                                                 java.lang.String delim)
Parces the string array into a string with delimiters separating each array indexes

Parameters:
sa - String[] - String array to be converted into a String
delim - String - the delimiter that will parce the string
Returns:
str - String

StringArrAddEl

public static java.lang.String[] StringArrAddEl(java.lang.String[] sa,
                                                java.lang.String str)
This function appends a string element to the end of the String array.

Parameters:
sa - String[] - a string array that needs an element to be added.
str - String - the element to be added.
Returns:
strArr[] - String[] - the string array with added element

IntArrAddEl

public static java.lang.Integer[] IntArrAddEl(java.lang.Integer[] iarr,
                                              int i)
This function appends a integer element to the end of the integer array.

Parameters:
iarr - Integer[] - the integer array that needs an element to be added.
i - int - the element to be added.
Returns:
intArr - Integer[] - the Integer array with the added element.

arrSplice

public static java.lang.Integer[] arrSplice(java.lang.Integer[] iarr,
                                            int pos)
Returns a new array that removes a single element from the input Integer array at a given position

Parameters:
iarr - Integer[] - the Integer array to be edited.
pos - int - the position from where the element is to be removed.
Returns:
intArr - Integer[] - the Integer array that has the specified element removed.

StringArrAddArr

public static java.lang.String[] StringArrAddArr(java.lang.String[] sa1,
                                                 java.lang.String[] sa2)
This method add two string arrays together.

Parameters:
sa1 - String[] - string array to be added.
sa2 - String[] - string array to be added.
Returns:
sa - String[] - added String array.

ByteArrToStringArr

public static java.lang.String[] ByteArrToStringArr(byte[] bt)
Converts byte array into string array.

Parameters:
bt - byte[] - byte array to be converted.
Returns:
String[]

StringArrToByteArr

public static byte[] StringArrToByteArr(java.lang.String[] strarr)
This method converts a String array to a byte array.

Parameters:
strarr - String[] - string array
Returns:
byte[]

StringToStringArr

public static java.lang.String[] StringToStringArr(java.lang.String str,
                                                   java.lang.String del)
This method converts a string to a string array using the specified delimiter.

Parameters:
str - String - string to be converted.
del - String - the delimiter to be used to parce the string.
Returns:
String[]

toInt

public static java.lang.Integer toInt(java.lang.String str)
Converts a string representaion of an integer to Integer class.

Parameters:
str - - String - string representaion of an integer
Returns:
integer - Integer

toString

public static java.lang.String toString(int i)
Converts an integer to string.

Parameters:
i - - int
Returns:
str - String

StringArrRemoveEl

public static java.lang.String[] StringArrRemoveEl(java.lang.String[] sa,
                                                   java.lang.String str)
This function removes a string element from a String array.

Parameters:
sa - String[] - a string array that needs an element to be removed.
str - String - the element to be removed.
Returns:
strArr[] - String[] - the string array with removed element, IF the element did not exist then it returns the original string array.

BinaryToString

public static java.lang.String BinaryToString(byte[] digest)
This method convets a byte array to a string where each byte is split into two characters providing the hex representation of the byte.

Parameters:
digest - byte[] - byte array to be converted
Returns:
String - the converted string.

StringToBinary

public static byte[] StringToBinary(java.lang.String str)
String to binary

Parameters:
str -
Returns:
byte[]

StringToInt

public static int StringToInt(java.lang.String str)
String to integer.

Parameters:
str - String - string number to be converted to int.
Returns:
i - int - int type number converted from string.

HexStringToInt

public static int HexStringToInt(java.lang.String str)

IntToString

public static java.lang.String IntToString(int i)
Integer to String.

Parameters:
i - int - int number to be converted to string
Returns:
str - String - string representation of the integer number

ByteArrAddArr

public static byte[] ByteArrAddArr(byte[] sa1,
                                   byte[] sa2)
This method add two byte arrays together.

Parameters:
sa1 - byte[] - byte array to be added.
sa2 - byte[] - byte array to be added.
Returns:
sa - byte[] - added byte array.

ByteArrAddEl

public static byte[] ByteArrAddEl(byte[] sa,
                                  byte str)
This function appends a byte element to the end of the byte array.

Parameters:
sa - byte[] - a byte array that needs an element to be added.
str - byte - the element to be added.
Returns:
strArr[] - byte[] - the byte array with added element

IntToByte

public static byte[] IntToByte(int i)
This method converts an integer into a byte array.

Parameters:
i - int - integer to be converted
Returns:
intB - byte[] - integer that has been converted to byte.

subByteArr

public static byte[] subByteArr(byte[] inbArr,
                                int start,
                                int end)
This method retrieves the specified sub array of a byte array passed in.

Parameters:
inbArr - byte[] - byte array to be subed from.
start - int - start index of the sub array.
end - int - end index of the sub array.
Returns:
subArr - byte[] - the sub array.

arrComp

public static boolean arrComp(byte[] b1,
                              byte[] b2)
This method compares two byte arrays.

Parameters:
b1 - byte[] - byte array to be compared
b2 - byte[] - byte array to be compared
Returns:
boolean Boolean: TRUE, if the game was created successfully, FALSE, otherwise

addVectorToVector

public static java.util.Vector addVectorToVector(java.util.Vector v1,
                                                 java.util.Vector v2)
This method adds two vectors together.

Parameters:
v1 - Vector - vector one
v2 - Vector - vector two
Returns:
Vector - the combined vector

VectorToStringArr

public static java.lang.String[] VectorToStringArr(java.util.Vector v)
This method converts a Vector to a string array.

Parameters:
v - Vector - vector to be converted
Returns:
String[]- converted String array

StringArrToVector

public static java.util.Vector StringArrToVector(java.lang.String[] strArr)
This method converts a string array to a vector.

Parameters:
strArr - String[] - string array to be converted
Returns:
Vector - converted vector

StringArrGETsubArr

public static java.lang.String[] StringArrGETsubArr(java.lang.String[] strArr,
                                                    int indexStart,
                                                    int indexEnd)
This method gets the sub array of a Stirng array.

Parameters:
strArr - String[] - the array from which the sub array will be extracted
indexStart - int - starting index.
indexEnd - int - ending index.
Returns:
String[] - the sub array.

ByteArrGETsubArr

public static byte[] ByteArrGETsubArr(byte[] strArr,
                                      int indexStart,
                                      int indexEnd)
This method gets the sub array of a Stirng array.

Parameters:
strArr - String[] - the array from which the sub array will be extracted
indexStart - int - starting index.
indexEnd - int - ending index.
Returns:
String[] - the sub array.

LongToString

public static java.lang.String LongToString(long i)
Long to String.

Parameters:
i - int - int number to be converted to string
Returns:
str - String - string representation of the integer number

StringToLong

public static long StringToLong(java.lang.String str)
String to Long.

Parameters:
str - String - string number to be converted to long
Returns:
l - long - long representation of the string number

compareStringArrays

public static boolean compareStringArrays(java.lang.String[] str1,
                                          java.lang.String[] str2)
Compares two string arrays if they contain identical items. The order does not matter, just as long as they contain number and same strings.

Parameters:
str1 -
str2 -
Returns:
boolean

SPclone

public static java.lang.String[] SPclone(java.lang.String[] strArr)
This method clones a string array and makes a copy. J2SE supports object cloning, but J2ME does not. Thus we created this method that calls the SPUInteropUtilClass.SPIclone method which in J2SE calls the object clone method, and in J2ME actually goes through the string array and copies it to a new string array.

Parameters:
strArr -
Returns:
String[]

SPclone

public static byte[] SPclone(byte[] byteArr)
This method clones a byte array and makes a copy. J2SE supports object cloning, but J2ME does not. Thus we created this method that calls the SPUInteropUtilClass.SPIclone method which in J2SE calls the object clone method, and in J2ME actually goes through the byte array and copies it to a new byte array.

Parameters:
byteArr -
Returns:
byte[]

registerTransaction

public static boolean registerTransaction(java.lang.String transName,
                                          SPAbstractTransactionInterface transInstance)
This method registers Transaction objects with so that they can be used in this library.

Parameters:
transName - String - transaction name
transInstance - SPAbstractTransactionInterface - the transaction object instance
Returns:
boolean

viewRegisteredTransaction

public static java.lang.String[] viewRegisteredTransaction()
This method allows users to see what transactions have been registered.

Returns:
String[]

getRegisteredTransaction

public static SPAbstractTransactionInterface getRegisteredTransaction(java.lang.String key)
This method gets a registered Transaction object from the register list and returns it to the user.

Parameters:
key - String - the name of the transaction.
Returns:
SPAbstractTransactionInterface

getTransactionRegistry

private static SPMap getTransactionRegistry()
This method returns the transaction registry list. It is set to private because no one should be able to edit it.

Returns:
SPMap

SPgenerateKey

public static java.lang.String SPgenerateKey(int keySize)
This function generates a "real" random key that is easily stored in a printable string. THIS FUNCTION SHOULD NOT BE USED FOR PRODUCTION GAMES. PLEASE USE A REAL RANDOM TOOL. THIS FUNCTION IS PROVIDED AS A SAMPLE ONLY

Parameters:
keySize - int - a positive value - should be large enough to generate a good range of keys. SecurePlay library examples use 25
Returns:
generatedkey - String - a base 62 0..9A..Za..z string

SPtransform

public static java.lang.String SPtransform(java.lang.String input,
                                           java.lang.String gameid)
This function performs an irreversible transform on an input string to generate an output string. The sample implementation uses MD5. This method can be overridden and should be reviewed for security purposes prior to use in a production implementation.

Parameters:
input - String
Returns:
str - String

getHashText

public static byte[] getHashText(java.lang.String plainText,
                                 java.lang.String algorithm)
This method gets the hashed string

Parameters:
plainText - String - string to be hashed
algorithm - String - The algorithm to use like MD2, MD5, SHA-1, etc.
Returns:
hash - String - the hashed string

SPclone

public static java.util.Hashtable SPclone(java.util.Hashtable htbl)
This method wraps the proper clone method of hashtable for ME and SE interoperability.

Parameters:
htbl - Hashtable - hashtable to be cloned.
Returns:
Hashtable - cloned hashtable.

isElementIncluded

public static boolean isElementIncluded(java.lang.String elem,
                                        java.lang.String[] array)
This method checks to see if an element is included in a string array.

Parameters:
elem - String - element to be checked.
array - String[] - string array to be checked.
Returns:
boolean - TRUE: if element exists in the array, FALSE: if the element does not exist in the array.

isElementIncluded

public static boolean isElementIncluded(java.lang.String elem,
                                        java.util.Vector array)
This method checks to see if an element is included in a vector.

Parameters:
elem - String - element to be checked.
array - Vector - vector to be checked.
Returns:
boolean - TRUE: if element exists in the vector, FALSE: if the element does not exist in the vector.

StringArrContainsEl

public static boolean StringArrContainsEl(java.lang.String[] arr,
                                          java.lang.String elem)
Checks to see if the array contains the specified element.

Parameters:
arr -
elem -
Returns:
boolean

XreferenceTwoArrays

public static int XreferenceTwoArrays(java.lang.String[] arr1,
                                      java.lang.String[] arr2)
Cross References two string array and returns number of same strings or mathces occured between two arrays.

Parameters:
arr1 - String[] - array one
arr2 - String[] - array two
Returns:
int

IsArrayIntersectionTrue

public static boolean IsArrayIntersectionTrue(java.lang.String[] arr1,
                                              java.lang.String[] arr2)
Cross References two string array and returns number of same strings or mathces occured between two arrays.

Parameters:
arr1 - String[] - array one
arr2 - String[] - array two
Returns:
int

ArrayIntersection

public static java.lang.String[] ArrayIntersection(java.lang.String[] arr1,
                                                   java.lang.String[] arr2)
Cross References two string array and returns the common strings or mathces occured between two arrays.

Parameters:
arr1 - String[] - array one
arr2 - String[] - array two
Returns:
int

getTime

public static long getTime()

getNextRandom

public static int getNextRandom()

SecurePlayLibray J2SE
v2.1

2006 Copyright Filed by IT GlobalSecure, Inc. All Rights Reserved. Not to be used without authorization by Author. SecurePlay, IT GlobalSecure, and IT Armor are registered trademarks by IT GlobalSecure, Inc. Software protected by software license, and one or more the following U.S. and International patent numbers: U.S. Patent 6,030,288, U.S. Patent 6,165,072, European Patent Office EP1016049A1,and World Intellectual Property Organization WO9912135C1 and additional filings worldwide.