.NET Development
How to generate a public/private key pair
Gravatar is a globally recognized avatar based on your email address. How to generate a public/private key pair
  Alejandro A Sosa
  All
  Mar 29, 2020 @ 08:51am

Hello everybody,

Good health to everyone !! May a treatment for COVID-19 be available SOON !!!!!!.

I want to encrypt/sign a conversation between two programs with a one time public/private key pair.

How do you generate such a pair with VFP code?

Thank you very much.

Alex

Gravatar is a globally recognized avatar based on your email address. re: How to generate a public/private key pair
  Rick Strahl
  Alejandro A Sosa
  Mar 29, 2020 @ 01:17pm

Here you go:

do wwDotNetBridge
LOCAL loBridge as wwDotNetBridge
loBridge = GetwwDotnetBridge()

loRSA = loBridge.CreateInstance("System.Security.Cryptography.RSACryptoServiceProvider",2048)
? loBridge.cErrorMsg

lcPublic = loRSA.ToXmlString(.F.)
lcPrivate = loRSA.ToXmlString(.T.)

? lcPublic
? lcPrivate

Now using that is a bit more of an exercise... The RSACryptoServiceProvider class allows you to load keys and verify them too.

What are you trying to do here? Applications rarely need this private/public encryption. This is more for big known entities where clients need to ensure the server they're talking to can be verified that the server is what they're claiming to be.

For application encryption you can just use symetric keys for two-way encryption or asymetric hashes for one way encryption (like user passwords)...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to generate a public/private key pair
  Alejandro A Sosa
  Rick Strahl
  Mar 29, 2020 @ 03:02pm

Good question. I know it's overkill but I confess I want to learn the technique.

The application is a web portal where our customers' employees ask questions that are resolved by sending an encrypted query to a program that is running alongside our desktop app. It's a Rube-Goldberg-contraption to provide a web interface to a desktop application.

Thanks for the answer.

Stay healthy !!!

Alex

© 1996-2024