Solved

C# ... Encryption & decryption RSA 2048

Posted on 2016-10-27
4
26 Views
Last Modified: 2016-11-16
#Encryption & decryption RSA 2048
Hi ,
I want to encrypt the text typed by user from text box and then encrypt that text by using public key  and save to db as cypher text. at that time private key to decrypt that cypher text has been generated at the same time. that generated private key is the only one that can decrypt the text .... later I retrive that cypher text from another page and need to decrypt that cypher text to original text using private key ... in this case ..., Where can I get the private key at that time.. and how can I do... anyone help me... pls thanks ... It means encryption and decryption is not occured at the same time...
0
Comment
Question by:Coral Coder
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Paweł earned 250 total points (awarded by participants)
ID: 41862033
Lets start with the idea of asymmetric encryption, in short a user generates two keys a public and a private one. Just as the names suggest you share the public one and keep the private one a secrete. the idea is that you encrypt with the public key, and de-crypt with the private key. that being said when you generate the two keys you would at that time store the private one in a super secrete location to use it for decryption later.

now I'm not 100% sure if you're using webforms, mvc, wpf, winrt, here's an example i made when i was exploring the topic for winrt

http://sharepoint-magic.blogspot.ch/2016/08/digital-signature-asymmetric-encryption.html

points of interest will be
  • GeneratePublicPrivateKeysForEncryption_Click
  • EncryptData_Click
  • Private_Decrypt_BTN_Click

as i recall there are different API's for winrt, so it may take some digging around by you, if you're not doing winRT i'd start at the following
https://msdn.microsoft.com/en-us/library/tswxhw92(v=vs.110).aspx
0
 
LVL 61

Assisted Solution

by:btan
btan earned 250 total points (awarded by participants)
ID: 41862516
For encryption of the text, suggest you consider symmetric instead of asymmetric as it is mostly use for small size block like key string. If the user text string is going to long and probably it is then symmetric encryption will be optimal for performance.

The symmetric encryption in this case can be via a pseudo random generated secret that is used to encrypt the text and then this same secret can be encrypted by your public key. The ciphertext and encrypted key can be combined (concatenated) and stored in the db as required. The private key is used to decrypt the secret which then is used to decrypt the ciphertext. You may considered the use of  Data Protection API. https://msdn.microsoft.com/en-us/windows/uwp/security/data-protection
0
 
LVL 8

Expert Comment

by:Paweł
ID: 41863701
Btan is spot on, asymmetric encryption isn't well suited for encrypting large amounts of data. As he says a great use of asymmetric encryption would be to generate a symmetric key and exchange it via asymmetric encryption, below is a nice explanation of what we're talking about.

http://mypathtowinrtdev.blogspot.ch/2014/06/securely-transferring-data.html
0
 
LVL 61

Expert Comment

by:btan
ID: 41889422
As suggested.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When the confidentiality and security of your data is a must, trust the highly encrypted cloud fax portfolio used by 12 million businesses worldwide, including nearly half of the Fortune 500.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now