Solved

C# ... Encryption & decryption RSA 2048

Posted on 2016-10-27
4
41 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 9

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 63

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 9

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 63

Expert Comment

by:btan
ID: 41889422
As suggested.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Provide an easy one stop to quickly get the relevant information on common asked question on Ransomware in Expert Exchange.
Encryption for Business Encryption (https://en.wikipedia.org/wiki/Encryption) ensures the safety of our data when sending emails. In most cases, to read an encrypted email you must enter a secret key that will enable you to decrypt the email. T…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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