473,951 Members | 25,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Encrypted File Transfer

Hi all,

the following problem occured to me and I hope somebody can
help me :

I need to implement an encrypted File download with
a PHP script on the server side and a c# client application.

I know there is a way to symmetrically encrypt files
with the php mcrypt routines and already did implement a
protocol based on xml for querying files from the
server.

So the problem is, I need to generate and exchange a
random key for each transfer. This is possible,
for example, with the Diffie-Hellman Key Exchange
Procedure. Because I found nothing about this
procedure in the php function list, I began
to implement it myself.

The problem in this case is that I need arithmetic
support for Big Numbers (>=1024 Bits). The bc* functions
are too slow and do not work in this case. An alternative
would be the GMP Library, which is not supported by the
ISP where the script will be running.

Setting up my own Server with GMP support is no alternative either in
this case.

So perhaps anybody knows how I could achieve an encrypted
file download with different keys for every "Download Session" in
php. Is it possible over an ssl / https connection ? Or what am I
missing here ?

I would be very grateful for any hints, tips, sugesstions, points
to existing code...

Many thanks in advance,

Philipp

Jul 17 '05 #1
8 5567
"Philipp Brune" <ph***********@ t-online.de> wrote in message
news:cs******** *****@news.t-online.com...
Hi all,

the following problem occured to me and I hope somebody can
help me :

I need to implement an encrypted File download with
a PHP script on the server side and a c# client application.

I know there is a way to symmetrically encrypt files
with the php mcrypt routines and already did implement a
protocol based on xml for querying files from the
server.

So the problem is, I need to generate and exchange a
random key for each transfer. This is possible,
for example, with the Diffie-Hellman Key Exchange
Procedure. Because I found nothing about this
procedure in the php function list, I began
to implement it myself.

The problem in this case is that I need arithmetic
support for Big Numbers (>=1024 Bits). The bc* functions
are too slow and do not work in this case. An alternative
would be the GMP Library, which is not supported by the
ISP where the script will be running.

Setting up my own Server with GMP support is no alternative either in
this case.

So perhaps anybody knows how I could achieve an encrypted
file download with different keys for every "Download Session" in
php. Is it possible over an ssl / https connection ? Or what am I
missing here ?

I would be very grateful for any hints, tips, sugesstions, points
to existing code...


Can't rely on a shared secret?
Jul 17 '05 #2
Philipp Brune <ph***********@ t-online.de> wrote:
The problem in this case is that I need arithmetic
support for Big Numbers (>=1024 Bits). The bc* functions
are too slow and do not work in this case.
The encryption doesn't have to be strong if you use SSL for the actual
transer. A weak onetime keypair has to be strong enough to allow the
transfer to complete before you can reasonably assume someone had the
processor time to crack it.

But is the openssl module (http://nl3.php.net/openssl) available on the
target server?
So perhaps anybody knows how I could achieve an encrypted
file download with different keys for every "Download Session" in
php. Is it possible over an ssl / https connection ? Or what am I
missing here ?


What is the quest? Should the file to download be encrypted during
transfer or should an encrypted file be downloaded to a client?

In the first case SSL is good enough but you could use DH key exchange
for authtication for additional security. I don't see the practical
point of the latter case.

Jul 17 '05 #3
Chung Leong schrieb:
"Philipp Brune" <ph***********@ t-online.de> wrote in message
news:cs******** *****@news.t-online.com...
Hi all,

the following problem occured to me and I hope somebody can
help me :

I need to implement an encrypted File download with
a PHP script on the server side and a c# client application.

I know there is a way to symmetrically encrypt files
with the php mcrypt routines and already did implement a
protocol based on xml for querying files from the
server.

So the problem is, I need to generate and exchange a
random key for each transfer. This is possible,
for example, with the Diffie-Hellman Key Exchange
Procedure. Because I found nothing about this
procedure in the php function list, I began
to implement it myself.

The problem in this case is that I need arithmetic
support for Big Numbers (>=1024 Bits). The bc* functions
are too slow and do not work in this case. An alternative
would be the GMP Library, which is not supported by the
ISP where the script will be running.

Setting up my own Server with GMP support is no alternative either in
this case.

So perhaps anybody knows how I could achieve an encrypted
file download with different keys for every "Download Session" in
php. Is it possible over an ssl / https connection ? Or what am I
missing here ?

I would be very grateful for any hints, tips, sugesstions, points
to existing code...

Can't rely on a shared secret?


Many thanks for your Reply !

But if you mean that Server and Client should agree
upon a key once and each store that key to be used
for every download session they will ever do, that
is not what I want.

A new Key for every Download is what I would appreciate !
Jul 17 '05 #4
Daniel Tryba schrieb:
Philipp Brune <ph***********@ t-online.de> wrote:
The problem in this case is that I need arithmetic
support for Big Numbers (>=1024 Bits). The bc* functions
are too slow and do not work in this case.

The encryption doesn't have to be strong if you use SSL for the actual
transer. A weak onetime keypair has to be strong enough to allow the
transfer to complete before you can reasonably assume someone had the
processor time to crack it.

But is the openssl module (http://nl3.php.net/openssl) available on the
target server?

So perhaps anybody knows how I could achieve an encrypted
file download with different keys for every "Download Session" in
php. Is it possible over an ssl / https connection ? Or what am I
missing here ?

What is the quest? Should the file to download be encrypted during
transfer or should an encrypted file be downloaded to a client?

In the first case SSL is good enough but you could use DH key exchange
for authtication for additional security. I don't see the practical
point of the latter case.


First of all, many thanks for your reply !

Well yes, the Provider has installed the OpenSSL module
on the Server, great !

To be more specifically, this is what I want to Achive :

1) Client and Server agree upon a one-time-key.
2) The Client POSTs an Xml String to the Server
in which he tells what file he wants to Download
and some additional Information :

<query filetodownload= "abc.def" package="packag eoffile">
<account>
<username>Phili pp</username>
<password>mypas s</password>
</account>
</query>

This POST should also be encrypted with the previously
agreed key.

3) Someone has Stored the file "abc.def" in unencrypted
form in a specific Directory (Protected by an .htaccess file)
on the Server before.

4) The Server Opens the file, encrypts the Data with the
key Exchanged in 1) and sends it to the Client.

5) The Client Decrypts the Data and stores it in a specific
Location.

There were two thougts came in my mind while I was reading your answer :

First, the Download of a file may take up to 30 minutes, for this
short time a smaller key of 128 Bit perhaps could not be cracked
I suppose. So I am going to test, if the bcmath functions
work with this.

Secondly, perhaps the whole Session (Step 1-5) could be
(semi-)transparently encrypted with ssl.
So I would like to know how this could be done, if possible !

Or if it would just be possible to exchange the key over ssl this would
be great! How can this be done ?

Perhaps something like this :

Server & Client establish HTTPS Connection.
Client POSTs a number of randomly generated
bytes to the Server.
The Server Replies with another number of
randomly generated bytes.
Both Quit the HTTPS Connection and
Calculate a Key with the Exchanged Bytes, perhaps
with a simple XOR or something like that.

Would this make sense ? How could it be done ?

Many thanks in advance for any help, suggestions, hints !


Jul 17 '05 #5
Philipp Brune <ph***********@ t-online.de> wrote:
There were two thougts came in my mind while I was reading your answer :

First, the Download of a file may take up to 30 minutes, for this
short time a smaller key of 128 Bit perhaps could not be cracked
I suppose. So I am going to test, if the bcmath functions
work with this.
The data itself should offcourse be strongly encrypted.
Secondly, perhaps the whole Session (Step 1-5) could be
(semi-)transparently encrypted with ssl.
So I would like to know how this could be done, if possible !
Ehhh, step 1 thru 5 are essentially SSL.
Or if it would just be possible to exchange the key over ssl this would
be great! How can this be done ?
https (http over ssl) is transparant, your PHP script and C# client
communicate just like any other http client/server. The client does a
for example a POST, the C# http/crypto libs will setup a secure
connection (I'd guess they use DH for that) to the webserver, which
invokes PHP. All data send from PHP will be over the already encrypted
socket back to the client. A typical encryption would be something like
AES-256 (which is symmetric)
Perhaps something like this :

Server & Client establish HTTPS Connection.
Client POSTs a number of randomly generated
bytes to the Server.
The Server Replies with another number of
randomly generated bytes.
Both Quit the HTTPS Connection and
Calculate a Key with the Exchanged Bytes, perhaps
with a simple XOR or something like that.

Would this make sense ? How could it be done ?


If you can use SSL this doesn't make any sense (way to complicated :).
SSL does the encryption (transparant), so all you have to do is
authenticate the client:

1-server/client establish https connection
2-client authenticates somehow (could be plaintext challenge/response)
3-server pushes file over existing socket

step 1 is handled by the actual webserver and the cryptolibraries on the
client
step 2 could be anything you want, from simple text passwords to RSA
step 3 could be a simple readfile() in PHP in response to a successfull
step 2

Alternatively (depending on how the client program get distributed) you
could do authentication with SSL by using self generated client certificates
(some kind of activation after install).
Jul 17 '05 #6
Daniel Tryba schrieb:
Philipp Brune <ph***********@ t-online.de> wrote:
There were two thougts came in my mind while I was reading your answer :

First, the Download of a file may take up to 30 minutes, for this
short time a smaller key of 128 Bit perhaps could not be cracked
I suppose. So I am going to test, if the bcmath functions
work with this.

The data itself should offcourse be strongly encrypted.


You are right, weak encryption is not what i should do to
minimize programming effort :-)
Secondly, perhaps the whole Session (Step 1-5) could be
(semi-)transparently encrypted with ssl.
So I would like to know how this could be done, if possible !

Ehhh, step 1 thru 5 are essentially SSL.

Or if it would just be possible to exchange the key over ssl this would
be great! How can this be done ?

https (http over ssl) is transparant, your PHP script and C# client
communicate just like any other http client/server. The client does a
for example a POST, the C# http/crypto libs will setup a secure
connection (I'd guess they use DH for that) to the webserver, which
invokes PHP. All data send from PHP will be over the already encrypted
socket back to the client. A typical encryption would be something like
AES-256 (which is symmetric)

Perhaps something like this :

Server & Client establish HTTPS Connection.
Client POSTs a number of randomly generated
bytes to the Server.
The Server Replies with another number of
randomly generated bytes.
Both Quit the HTTPS Connection and
Calculate a Key with the Exchanged Bytes, perhaps
with a simple XOR or something like that.

Would this make sense ? How could it be done ?

If you can use SSL this doesn't make any sense (way to complicated :).
SSL does the encryption (transparant), so all you have to do is
authenticate the client:

1-server/client establish https connection
2-client authenticates somehow (could be plaintext challenge/response)
3-server pushes file over existing socket

step 1 is handled by the actual webserver and the cryptolibraries on the
client
step 2 could be anything you want, from simple text passwords to RSA
step 3 could be a simple readfile() in PHP in response to a successfull
step 2

Alternatively (depending on how the client program get distributed) you
could do authentication with SSL by using self generated client certificates
(some kind of activation after install).

Yes, I suppose the best solution is to use SSL, why reinvent the wheel ?
I think the client-certificate seems to be a great way for
authentication, so I am now going to read a lot about OpenSSL and
certificates to see how this technique best fits into my
project! Google will help me find the Tutorials/Code samples I need
(hope so).

I am very grateful for your answer ! Thank you alot !
Jul 17 '05 #7
Philipp Brune <ph***********@ t-online.de> wrote:
Yes, I suppose the best solution is to use SSL, why reinvent the wheel ?
Indeed.
I think the client-certificate seems to be a great way for
authentication, so I am now going to read a lot about OpenSSL and
certificates to see how this technique best fits into my
project! Google will help me find the Tutorials/Code samples I need
(hope so).


It does, but I bookmarked this last time I needed to generate a
seflsigned CA and client certificates with openssl (not for/in PHP
though): http://linsec.net/info/ssl-cert.html

Jul 17 '05 #8
In essence, yes. Although you can use the the shared secret to encrypt
a new key each time, which is used to encrypt the actual data.
What I was really asking is whether your system employs passwords.

Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
2884
by: zn | last post by:
If I place a form for product ordering on my website, what scripting technology or CGIs can I use to encrypt the e-mail sent to my e-mail account with the order information? Thanks.
2
6023
by: Jill Elaine | last post by:
I am building an Access 2002 frontend with linked tables to an encrypted Paradox 7 database. When I first create these linked tables, I'm asked for the password to the encrypted Paradox database, and the linked tables are successfully created. I use the data from these linked tables in several forms. All works great until I close the Access frontend and open it again. When I try to use the forms, I get an error message: "Could not...
2
5159
by: Leonardo D'Ippolito | last post by:
Hi! I have two .NET win apps that need to communicate on a TCP/IP network. 'App A' must ask 'app B' if it's allowed to do some task, and 'app B' must authorize or prohibit it. How can I do this kind of communication in a secure way (protected from sniffing)? It would be a very simple protocol. Question, and two possible answers 'yes' or 'no'.
4
5536
by: Debbie Carter | last post by:
Would anyone know how to read the file attributes of a file on the hard drive to check if the file is encrypted or not? I have searched Visual Studio Help and MSDN and the samples I have found do not work. Any help would be appreciated. I am using VB.NET
4
2419
by: nepdae | last post by:
Well, after reading and hunting all over the web, including here, I still haven't been successful in my attempts to resolve my situation. So, I thought maybe I'd just ask. Here's the situation: I have an Access 2000 database (~15 users), split into a front- and back-end. Each user has a local copy of a workgroup file and the data file is out on a server. The problem started when the IS department upgraded the server at night, touching...
8
2790
by: robert | last post by:
Hello, I want to put (incrementally) changed/new files from a big file tree "directly,compressed and password-only-encrypted" to a remote backup server incrementally via FTP,SFTP or DAV.... At best within a closed algorithm inside Python without extra shell tools. (The method should work with any protocol which allows somehow read, write & seek to a remote file.) On the server and the transmission line there should never be...
5
6796
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would cause. If I could create a large file that could be encrypted, and maybe add files to it by appending them and putting in some kind of delimiter between files, maybe a homemade version of truecrypt could be constructed. Any idea what it...
3
1934
by: phforum | last post by:
I have no ideas to encrypt the user input password from the text box.....
1
1604
by: vermarajeev | last post by:
Hi guys, I have a plain text file. I want to encrypt and send this file via mail. I use SMTP to send the file over network. I'm able to send the file in plain text but if I encode and send it, I get some stupid data. I make use of base64 to encode the file. Here is the tags with data that I send to mail server. MIME-Version: 1.0 From: abc@gmail.com To: xyz@yahoo.com Subject: Hi Content-Type: multipart/mixed; boundary=unique-boundary-1...
0
10174
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8277
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6237
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3565
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.