encrypt a string, then decrypt it

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

I want to have one machine encypt a string value(in memory not disk), and
then pass that new value to another machine, where it will be decrypted back
to its original value.

I have no idea on this sort of stuff, but I figure it is possible.

Any good place I can go to read up on this, or perhaps grab some sample
code.
 
I want to have one machine encypt a string value(in memory not disk), and
then pass that new value to another machine, where it will be decrypted back
to its original value.

I have no idea on this sort of stuff, but I figure it is possible.

Any good place I can go to read up on this, or perhaps grab some sample
code.

As much as Microsoft has worked to make encryption easy in .net, it's
still not very easy.

Look in the System.Cryptography namespace, particularly the
RSAServiceProvider class.

The methodology is this:

1. Have the *receiving* machine generate an RSA key and send the
Public Key part of it to the sending machine as part of a request for
the string.

2. The sending machine encrypts the string with the public key it was
provided and sends it out.

3. The receiving machine decrypts the string using the private key it
has generated.
 
If you are planning on using NetworkStreams to send the encrypted
message between the machines, you need to be careful. Make sure that
you receive the entire encrypted message from the stream before you
try to decrypt it. If you feed the stream directly into the decryptor,
you may produce an error as not all of the data may be immediately
present to decrypt the blocks, due to network latency.

I demonstrate how to do this in chapter 17 of my "C# Network
Programming" book. You can freely download the code from the Sybex web
site. Of course the examples are in C#, but you should be able to
convert them to VB.NET fairly easily. Good luck with your project.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471433012.html
 
Back
Top