[Java] Conquer blowfish cipher implementation

04/13/2011 14:00 shitboi#1
Since tomas has been putting so much effort into building his proxy, I'll put up my codes for blowfish cipher so that I can help ttomas and any other java developers out there.

The main class that you will need is the BlowFishCryptor. It's a easy to use wrapper that I wrote for the other 2 blowfish classes. The other 2 files are directly translated from openssl library, and i think it is done by some guru from this forum; sparkie knows who that person is; i do not think he will mind me sharing his codes ")

Before you use them, make sure you change the package title in the codes

here is a sample of how the cryptor object should be invoked.
I have had all my ciphers implementing ConquerCipher interface. It is really up to you if you want to do that; amend your codes necessarily if you not. I have included the interface in the downloads as well.
Though this is redundant, just incase you're mentally blocked from chewing your codes and others, the way to declare cipher without implementing ConquerCipher interface is:
private/public BlowFishCryptor aCipher;
Code:
private ConquerCipher DHcipher = new GameCryptographer(), ServerCipher = null, ClientCipher = null;

The key BlowFishCryptor accepts is the 64 byte array generated by KeyAgreement.getSecret();
Code:
ServerCipher = new BlowFishCryptor(dhhandler.getProxyServerKey(), dhhandler.getServerIV(), dhhandler.getClientIV());
ClientCipher = new BlowFishCryptor(dhhandler.getProxyClientKey(), dhhandler.getClientIV(), dhhandler.getServerIV());
After instantiating your ciphers, ServerCipher can encrypt and decrypt packets between proxy and server. ClientCipher can encrypt and decrypt packets between proxy and client.
04/13/2011 14:08 TomasLT#2
Thank you so much. What would I do without you :D

Still i have some question. How to be sure that generated ProxyServer/ProxyClient sared key is correct ? bcouse Decrypted packets dont make any sense. No TO signature in the end of the packets

Code:
public void GetProxyClientKey(String CpKey) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, InvalidAlgorithmParameterException, IOException{
		cpublicKey = new DHPublicKeySpec(new BigInteger(CpKey,16), p, g); //p ir g = null !!!
		KeyAgreement ka2=KeyAgreement.getInstance("DiffieHellman");
	    KeyFactory kf2 = KeyFactory.getInstance("DiffieHellman");
	    PublicKey PubKey2=kf2.generatePublic(cpublicKey);
        ka2.init(privateKey);
        ka2.doPhase(PubKey2, true);
        byte[] SharedSecret2=ka2.generateSecret();
        ClientShared = new BigInteger(SharedSecret2);
        ClientSharedarray = ClientShared.toByteArray();
	}
And here is how do i de/en
Code:
BlowFishCryptor ServerCipher = new BlowFishCryptor(de.ServerSharedarray, bc.serverIV, bc.clientIV);
						BlowFishCryptor ClientCipher = new BlowFishCryptor(de.ClientSharedarray, bc.clientIV, bc.serverIV);
ServerCipher.Decrypt(buffer2);
						Print2("from Server2 " +sizeFromServer +" : ",buffer2);
						ClientCipher.Encrypt(buffer2);
04/25/2011 22:23 taushif#3
uhhm attributes/variables & methods must/should not be written with Capitals lol :p
04/26/2011 02:56 IAmHawtness#4
Quote:
Originally Posted by taushif View Post
uhhm attributes/variables & methods must/should not be written with Capitals lol :p
Really? I always thought that was kinda old-fashioned to write variable names without capitalization. We've always been taught to write variables like
FirstName, LastName, SelectedClient, etc.
04/26/2011 03:02 shitboi#5
Quote:
Originally Posted by IAmHawtness View Post
Really? I always thought that was kinda old-fashioned to write variable names without capitalization. We've always been taught to write variables like
FirstName, LastName, SelectedClient, etc.
he must be a good student, since he is sticking to the java convention so well, hahaha
04/26/2011 03:06 IAmHawtness#6
Quote:
Originally Posted by shitboi View Post
he must be a good student, since he is sticking to the java convention so well, hahaha
Hahaha, indeed :)