0

I'm trying to make an program that send a file to a mobile device encrypted, and the device will get it in another program and decrypt it.

So far I've done the bluetooth connection:

private void Connect()
{
    using (SelectBluetoothDeviceDialog bldialog = new SelectBluetoothDeviceDialog())
    {
        bldialog.ShowAuthenticated = true;
        bldialog.ShowRemembered = true;
        bldialog.ShowUnknown = true;

        if (bldialog.ShowDialog() == System.Windows.Forms.DialogResult.OK )
        {
            if (bldialog.SelectedDevice == null)
            {
                System.Windows.Forms.MessageBox.Show("No device selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            BluetoothDeviceInfo selecteddevice = bldialog.SelectedDevice;
            BluetoothEndPoint remoteEndPoint = new BluetoothEndPoint(selecteddevice.DeviceAddress, BluetoothService.ObexFileTransfer);

            client = new BluetoothClient();
            client.Connect(remoteEndPoint);

            session = new ObexClientSession(client.GetStream(), UInt16.MaxValue);
            session.Connect(ObexConstant.Target.FolderBrowsing);
            tbConnectionDet.Text = string.Format("Connected to: {0}", selecteddevice.DeviceName);
        }
    }
}

Also I'm sending the file this way:

 private void UploadFiles(string[] files)
    {
        long size = 0;
        List<string> filestoupload = new List<string>();

        foreach (string filename in files)
        {
            if (File.Exists(filename))
            {
                FileInfo info = new FileInfo(filename);
                filestoupload.Add(filename);
                size += info.Length;
            }
        }

        using (FileForm upform = new FileForm(new List<string>(filestoupload),
                                              false, session, size, null))
        {
            upform.ExceptionMethod = ExceptionHandler;
            upform.ShowDialog();


            lsvExplorer.BeginUpdate();
            for (int i = 0; i <= upform.FilesUploaded; i++)
            {
                ListViewItem temp = new ListViewItem(new string[]{ Path.GetFileName(filestoupload[i]),
                                                                   FormatSize(new FileInfo(filestoupload[i]).Length, false)},
                                                     GetIconIndex(Path.GetExtension(filestoupload[i]), false));
                temp.Tag = false;
                lsvExplorer.Items.Add(temp);
            }
            lsvExplorer.EndUpdate();
        }
    }

I'm using 32feet and BrechamObex libraries .

I have the following questions :

  1. I want to send a public key from my phone to my computer then encrypt a file and send it back to my phone. After I receive the file, I want to decrypt it so I will need another program in order to do this. How can I send information from one program to another using bluetooth?

  2. Whenever I send a file, the phone gets it, but the size it always 0

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Spoukey
  • 15
  • 6
  • I'm not fully understanding your 1. question. Do you want to save your files first, than let another program encrypt them and then send them? – Hannes Apr 22 '17 at 18:18
  • Sorry i lost my thought there for a moment .Edit – Spoukey Apr 22 '17 at 18:24
  • Why don't you use something like this `var buffer = System.Text.Encoding.UTF8.GetBytes("Whatever you want to send"); var stream = client.GetStream(); stream.Write(buffer, 0, buffer.Length); stream.Flush(); stream.Close(); ` to send something? – Hannes Apr 22 '17 at 18:44

0 Answers0