473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

RSACryptoServiceProvider Question

I have a x509Certificate that I exported and I am using for testing called
wsTest.cer.pfx. I want to use this cert to send a public key to anyone who
requests it, and then use the private key to decrypt any incoming messages.
In the code below you can see I can grab the publickey string from this cert
and pass it back to the client. I can also create a
RSACryptoServiceProvider from the cert.private key. This is all good and
fine. What I am trying to do, is write the client code that could
encrypt/decrypt messages from the server using the public key, and write
code that would encrypt/decrypt using the private key. Anyone have code
that would do this. I have looked on google with little success.

John

Dim cert As New X509Certificate2("[cert location]", "password")

Dim rsa As RSACryptoServiceProvider = CType(cert.PrivateKey,
RSACryptoServiceProvider)

With cert

TextBox4.Text = .GetKeyAlgorithm

TextBox6.Text = .GetCertHashString & vbCrLf

TextBox5.Text = .PrivateKey.ToString

TextBox6.Text &= .GetPublicKeyString

TextBox5.Text = .GetRawCertDataString

MsgBox(.HasPrivateKey)

End With

Jun 28 '07 #1
3 4183
Hi John,

If I understand you correctly, you want to take the certificate,
distribute the public key, and then use asymmetric encryption for the
safeguarding of transferred information.

Can I make a suggestion? I would approach the problem just a little
differently. Asymmetric encryption is very processor intensive, and as
such slower to encrypt and decrypt than symmetric. To achieve the same
levels of encryption / safety you also would need much larger keys for
asymmetric than you would for symmetric. So what I would suggest is
this:

1/ Distribute your public key far and wide - or use a service as sa
key provider to get around the key distribution problem.

2/ Settle on a standard of Symmetric encyption to use for the actual
data payload

3/ Generate a unique (one-time) passphrase and temporarily store it
(in memory not on the hard drive)

4/ Use the appropriate key (if you are the source then the private
key) to encrypt a copy of the one-time passphrase and store this
encrypted passphrase in memory (again not on the hard drive)

5/ Take you message that you wish to transfer, and encrypt it with a
symmetric algorithm, such as AES, with the passphrase (unencrypted
version of the passphrase)

6/ Store the encrypted message somewhere (hard drive is okay for this)

7/ Attach the encrypted passphrase to the message, in a way that you
are able to separate out the encrypted key later for retreival.

8/ I would also suggest generating an MD5 hash for the unencrypted
message so that you can verify that the message is decrypted properly
at the other end, and attach this to the encrypted message as well in
such a way that it can be separated.

9/ Send the encypted message + encrypted passphrase + MD5 to the
recipient

10/ At the other end reverse the process (ie/ use public key to
decrypt the passphrase, then use passphrase to decrypt the message,
then check the message against the MD5 hash to see that it is correct.

You can find a simple and clean example of .net cryptography for the
AES algorithm here:

http://www.codeproject.com/dotnet/EncryptFile.asp

It should give you most all of what you need to get the job done.

I hope this points you in the right direction

Cheers

The Frog

Jun 29 '07 #2
I figured our the problem. Skipping the certificates and just using the
rsaCryptoProvider. I pass the public key to the client via a web service
call, the client encrypts its symmetric password with the key and passes the
encrypted key and data to the server which decrypts the password then uses
this password to decrypt the payload.

John
"John Wright" <ri***********@hotmail.comwrote in message
news:et**************@TK2MSFTNGP03.phx.gbl...
>I have a x509Certificate that I exported and I am using for testing called
wsTest.cer.pfx. I want to use this cert to send a public key to anyone who
requests it, and then use the private key to decrypt any incoming messages.
In the code below you can see I can grab the publickey string from this
cert and pass it back to the client. I can also create a
RSACryptoServiceProvider from the cert.private key. This is all good and
fine. What I am trying to do, is write the client code that could
encrypt/decrypt messages from the server using the public key, and write
code that would encrypt/decrypt using the private key. Anyone have code
that would do this. I have looked on google with little success.

John

Dim cert As New X509Certificate2("[cert location]", "password")

Dim rsa As RSACryptoServiceProvider = CType(cert.PrivateKey,
RSACryptoServiceProvider)

With cert

TextBox4.Text = .GetKeyAlgorithm

TextBox6.Text = .GetCertHashString & vbCrLf

TextBox5.Text = .PrivateKey.ToString

TextBox6.Text &= .GetPublicKeyString

TextBox5.Text = .GetRawCertDataString

MsgBox(.HasPrivateKey)

End With

Jun 29 '07 #3
Hi John,

Sounds neat and sweet.

Cheers

The Frog

Jul 3 '07 #4

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

Similar topics

0
by: Sam johnson | last post by:
Hi I'm using the RSACryptoServiceProvider class in one of my applications, but I still don't know what to enter as a first param in the following construction dim rsa as new...
1
by: mYsZa | last post by:
Hi all! I've got really strange (for me) problem: I've got an application, that at startup decrypts some data. Everything works fine - the rijndael key is decrypted using the...
1
by: news.bt.com | last post by:
I'm currently trying to strengthen up the security on a large ASP.NET application. I use MD5 hashes for the user/password, and a token to 'salt' the resultant hash. This is secure. The next step...
0
by: vooose | last post by:
Does anyone know anything detailed about what happens when you declare a new instance of RSACryptoServiceProvider? ie //Create a new RSACryptoServiceProvider object. RSACryptoServiceProvider...
0
by: khubieb | last post by:
Simply I am trying to use RSACryptoServiceProvider to generate a key pair, send the public key to a service that will retrieve me data, encrypt it with my public key, send the encrypted data back...
0
by: Ismail Fatih Yıldırım | last post by:
I modified the RSACSPSample from MSDN to try out a simple commutative encryption model using RSA encryption but when i run the progrem the first encryption command works but during the second...
2
by: =?Utf-8?B?R2FicmllbCBNw6luZGV6?= | last post by:
Hello everyone. I have a small class that encapsulates some functionallity to work with the RSACryptoServiceProvider. Here is the code of the class i'm using: public class dsRSA { private...
0
by: dfa_geko | last post by:
Hi All, Just had a question about the RSACryptoServiceProvider class. I'm kind of a newbie at this. In the following code at the end of the message, does the key get stored in the User...
0
by: Olli Goessler | last post by:
Hi Guys, (sorry for my bad english) i have a question for the following problem: With the RSACryptoServiceProvider object... Application A: // Generate a public/private key pair....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.