Solved

C# ... Encryption & decryption RSA 2048

Posted on 2016-10-27
4
44 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
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…

726 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