private byte[] encrypt(EncryptableObject o, Key key) throws Exception{
		String Algrithem;
		if(key instanceof PublicKey){Algrithem = "RSA";}
		else{Algrithem = "AES";}
		ByteArrayInputStream i = new ByteArrayInputStream(o.toByteArray());
		Cipher cipher = Cipher.getInstance(Algrithem);
		cipher.init(Cipher.ENCRYPT_MODE, key);
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		CipherOutputStream ciph = new CipherOutputStream(out, cipher);
		byte[] buf = new byte[2048];
		int read;
		while((read=i.read(buf))!=-1){//reading data
			ciph.write(buf,0,read);  //writing encrypted data
			ciph.flush();
		}
		out.close();
		ciph.close();
		i.close();
		return out.toByteArray();
	}