• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

C# ... Encryption & decryption RSA 2048

#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
Coral Coder
Asked:
Coral Coder
  • 2
  • 2
2 Solutions
 
PawełSharePoint DeveloperCommented:
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
 
btanExec ConsultantCommented:
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
 
PawełSharePoint DeveloperCommented:
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
 
btanExec ConsultantCommented:
As suggested.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now