|
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--SHA1
This Java Class consists the server side for the wondeful JavaScript library 'sha1.js'. I wrote it because I basically needed some cheap client/server login authentication by the usual key/data system. Besides, I got the creeps watching the password posted unencrypted via http requests. This class makes sure that if your client is using the 'sha1.js' to encrypt the password with a key sent by the server, you can always repeat the encrypting on the server side (using the same key) and compare the encrypted strings. Since anyone who is trapping the http requests can actually send you the same encrypted string, I suggest you use the client's IP address as the base for the key generation. Since IP address spoofing is not a problem, this authentication method is not a very secured solution. If you need a full proof solution use ssl. However, this one, sure beats nothing. Feel free to do with it whatever you want
This Class is an Abstract Class, to make sure you do not create any new instances of it. It does not throw any exceptions and the code is much more 'C' like than pure object oriented. There are no implemented interfaces and no inheritance in use. In fact, it is written as close as possible to the original JavaScript code. I did not test tweaking the instance variables but if you do change them, make sure to apply the same change in the 'sha1.js' library or you won't get the same encrypted strings. You can call each one of the 6 work methods by using something like: SHA1.hex_hmac_sha1("key", "data"); They are the only public methods. All are public and static. You have no reason to call the private ones anyway.
The 'sha1.js' is a JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined in FIPS PUB 180-1. JavaScript Version 2.1 Copyright Paul Johnston 2000 - 2002. Other contributors to JavaScript version: Greg Holt, Andrew Kepert, Ydnar, Lostinet Distributed under the BSD License
See http://pajhome.org.uk/crypt/md5 for details.
Author: T.N.Silverman (C.T.Xm - SiA Riga, LV) mailto:tnsilver@ctxm.com
Creation date: (3/27/2004 5:57:00 PM)
Don't forget to visit my company, CTXM site at http://www.ctxm.com where you will find reference to all of the games this code is used in.
Field Summary | |
private static java.lang.String |
b64pad
|
private static int |
chrsz
|
private static boolean |
hexcase
|
Constructor Summary | |
SHA1()
|
Method Summary | |
static java.lang.String |
b64_hmac_sha1(java.lang.String key,
java.lang.String data)
This is one of the functions you'll usually want to call It take a string arguments and returns either hex or base-64 encoded strings Creation date: (3/27/2004 6:05:10 PM) |
static java.lang.String |
b64_sha1(java.lang.String s)
This is one of the functions you'll usually want to call It take a string argument and returns either hex or base-64 encoded strings Creation date: (3/27/2004 6:05:10 PM) |
private static java.lang.String |
binb2b64(int[] binarray)
Convert an array of big-endian words to a base-64 string Creation date: (3/27/2004 6:05:10 PM) |
private static java.lang.String |
binb2hex(int[] binarray)
Convert an array of big-endian words to a hex string. |
private static java.lang.String |
binb2str(int[] bin)
Convert an array of big-endian words to a string Creation date: (3/27/2004 6:05:10 PM) |
private static int |
bit_rol(int num,
int cnt)
Bitwise rotate a 32-bit number to the left. |
private static java.lang.String |
cleanB64Str(java.lang.String str)
Cleans a base64 String from all the trailing 'A' or other characters put there by binb2b64 that made the bin array 4 times larger than it originally was. |
private static int[] |
complete216(int[] oldbin)
Makes an int array of a length less than 16 an array of length 16 with all previous cells at their previous indexes. |
private static int[] |
concat(int[] oldbin,
int[] newbin)
Joins two int arrays and return one that contains all the previous values. |
private static int[] |
core_hmac_sha1(java.lang.String key,
java.lang.String data)
Calculate the HMAC-SHA1 of a key and some data Creation date: (3/26/2004 1:05:01 PM) |
private static int[] |
core_sha1(int[] x,
int len)
Calculate the SHA-1 of an array of big-endian words, and a bit length Creation date: (3/26/2004 1:05:01 PM) |
private static void |
doTest()
Just a test function to output the results of the 6 working funcions to the standard out. |
static java.lang.String |
hex_hmac_sha1(java.lang.String key,
java.lang.String data)
This is one of the functions you'll usually want to call It take a string arguments and returns either hex or base-64 encoded strings Creation date: (3/27/2004 6:05:10 PM) |
static java.lang.String |
hex_sha1(java.lang.String s)
This is one of the functions you'll usually want to call It take a string argument and returns either hex or base-64 encoded strings Creation date: (3/27/2004 6:05:10 PM) |
private static int |
rol(int num,
int cnt)
Bitwise rotate a 32-bit number to the left. |
private static int |
safe_add(int x,
int y)
Add ints, wrapping at 2^32. |
private static int |
sha1_ft(int t,
int b,
int c,
int d)
Perform the appropriate triplet combination function for the current Creation date: (3/26/2004 1:05:01 PM) |
private static int |
sha1_kt(int t)
Determine the appropriate additive constant for the current iteration Creation date: (3/26/2004 1:05:01 PM) |
private static boolean |
sha1_vm_test()
This is a boolean returnig test function that exists in the sha1.js library. |
static java.lang.String |
str_hmac_sha1(java.lang.String key,
java.lang.String data)
This is one of the functions you'll usually want to call It take a string arguments and returns either hex or base-64 encoded strings Creation date: (3/26/2004 1:05:01 PM) |
static java.lang.String |
str_sha1(java.lang.String s)
This is one of the functions you'll usually want to call It take a string argument and returns either hex or base-64 encoded strings Creation date: (3/26/2004 1:05:01 PM) |
private static int[] |
str2binb(java.lang.String str)
Convert an 8-bit or 16-bit string to an array of big-endian words In 8-bit function, characters >255 have their hi-byte silently ignored. |
private static int[] |
strechBinArray(int[] oldbin,
int size)
increase an int array to a desired sized + 1 while keeping the old values. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private static final boolean hexcase
private static final java.lang.String b64pad
private static final int chrsz
Constructor Detail |
public SHA1()
Method Detail |
public static java.lang.String b64_hmac_sha1(java.lang.String key, java.lang.String data)
key
- java.lang.Stringdata
- java.lang.Stringpublic static java.lang.String b64_sha1(java.lang.String s)
s
- java.lang.Stringprivate static java.lang.String binb2b64(int[] binarray)
binarray
- int[]private static java.lang.String binb2hex(int[] binarray)
binarray
- int[]private static java.lang.String binb2str(int[] bin)
bin
- int[]private static int bit_rol(int num, int cnt)
num
- intcnt
- intprivate static java.lang.String cleanB64Str(java.lang.String str)
str
- java.lang.Stringprivate static int[] complete216(int[] oldbin)
str
- java.lang.Stringprivate static int[] concat(int[] oldbin, int[] newbin)
str
- java.lang.Stringprivate static int[] core_hmac_sha1(java.lang.String key, java.lang.String data)
x
- java.lang.String[]len
- intprivate static int[] core_sha1(int[] x, int len)
x
- java.lang.String[]len
- intprivate static void doTest()
public static java.lang.String hex_hmac_sha1(java.lang.String key, java.lang.String data)
key
- java.lang.Stringdata
- java.lang.Stringpublic static java.lang.String hex_sha1(java.lang.String s)
s
- java.lang.Stringprivate static int rol(int num, int cnt)
num
- intcnt
- intprivate static int safe_add(int x, int y)
num
- intcnt
- intprivate static int sha1_ft(int t, int b, int c, int d)
t
- intb
- intc
- intd
- intprivate static int sha1_kt(int t)
t
- intprivate static boolean sha1_vm_test()
s
- java.lang.Stringpublic static java.lang.String str_hmac_sha1(java.lang.String key, java.lang.String data)
key
- java.lang.Stringdata
- java.lang.Stringpublic static java.lang.String str_sha1(java.lang.String s)
s
- java.lang.Stringprivate static int[] str2binb(java.lang.String str)
str
- java.lang.Stringprivate static int[] strechBinArray(int[] oldbin, int size)
str
- java.lang.String
|
XG Project | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |