Jump to content

Check out our Community Blogs


Member Since 20 Mar 2011
Offline Last Active Oct 24 2012 10:20 AM

Posts I've Made

In Topic: Encrypt large SealedObject

20 March 2012 - 03:48 AM

Here is the Exception:
Exception in thread "main" javax.crypto.IllegalBlockSizeException: Data must not be longer than 245 bytes
	at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:337)
	at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:382)
	at javax.crypto.Cipher.doFinal(Cipher.java:2086)
	at javax.crypto.SealedObject.<init>(SealedObject.java:172)
	at AuctionSecurity.encryptMessage(AuctionSecurity.java:71)
	at AuctionImpl.authUser(AuctionImpl.java:91)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
	at sun.rmi.transport.Transport$1.run(Transport.java:177)
	at sun.rmi.transport.Transport$1.run(Transport.java:174)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)
	at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
	at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
	at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160)
	at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
	at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
	at $Proxy0.authUser(Unknown Source)
	at ClientSeller.main(ClientSeller.java:61)

Here what Server is trying to do:

Key secretKey = ausec.generateDES();
		int rndNum = new Random().nextInt(90000);
		SealedObject reply_obj = ausec.encryptMessage(new UserAuthorisation(userRnd, rndNum, secretKey));

and here is my encryption/decryption class:

public void sendMessage(String to) throws IOException, NoSuchAlgorithmException, 
		File f = new File("keys//"+to+"_public.key");
		FileInputStream fis = new FileInputStream(f);
		byte[] enpubK = new byte[(int)f.length()];

		KeyFactory keyFactory = KeyFactory.getInstance("RSA");
		X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(enpubK);
		pubkey = keyFactory.generatePublic(publicKeySpec);

public SealedObject encryptMessage(Serializable message) throws InvalidKeyException, NoSuchAlgorithmException, 
	NoSuchPaddingException, IllegalBlockSizeException{
			Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
			cipher.init(Cipher.ENCRYPT_MODE, pubkey);
			Key secretKey = generateDES();
			SealedObject so;
			so = new SealedObject(secretKey, cipher);
			return so;
		catch (IOException e) {
		return null;

//next decryption

**Please ignore previous version

In Topic: Achieve authentication using public keys

19 March 2012 - 06:53 AM

wim DC thanks for quick response. I think your answer is not what I'm looking for and that's my fault. My project is based on Java RMI so now I'm trying to implement a kind of security between server and clients. So I'm generating a pair of keys for each and now I'm looking a way to confirm that this client is who

In Topic: Acknowledgement between client/server - C

13 December 2011 - 10:34 AM

Hello fayyazlodhi ,

Thanks for response. You are right I'm not good on this :( . Basically I have a .c file that contains main method and creates two threads. Client and Server. I have access just on those two files. Those files have three methods each and with a way I have to create a code that when Client request a connection, server answer back if connection established in order to move on or to try again. If connection established client should send three data packets that server should take and answer for each one back to the client, received or not received in order client re-transmit it . At the end when all three packets received from server, client need to send a final ("end") packet that notifying server to close the connection. Server response back that got the data, close the socket and client when received server's confirmation close its socket.

Is more clear now?

In Topic: Problem with Aero Window

03 December 2011 - 07:59 PM

Oh sorry, I thought you were saying something about my last question :)

In Topic: Problem with Aero Window

03 December 2011 - 07:46 PM

Removed, what?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download