Click here to Skip to main content
15,898,942 members
Home / Discussions / C#
   

C#

 
GeneralRe: string to string array Pin
Ed.Poore8-Jun-06 8:19
Ed.Poore8-Jun-06 8:19 
GeneralRe: string to string array Pin
Wjousts7-Jun-06 11:28
Wjousts7-Jun-06 11:28 
QuestionForce the Setup to RollBack()? [modified] Pin
Endren7-Jun-06 10:17
Endren7-Jun-06 10:17 
QuestionRSA Private Key Security Pin
Clonus7-Jun-06 10:00
Clonus7-Jun-06 10:00 
AnswerRe: RSA Private Key Security Pin
Ed.Poore7-Jun-06 10:37
Ed.Poore7-Jun-06 10:37 
GeneralRe: RSA Private Key Security Pin
Clonus8-Jun-06 2:59
Clonus8-Jun-06 2:59 
GeneralRe: RSA Private Key Security Pin
Clonus8-Jun-06 3:56
Clonus8-Jun-06 3:56 
GeneralRe: RSA Private Key Security Pin
Ed.Poore8-Jun-06 8:11
Ed.Poore8-Jun-06 8:11 
It all depends on how secure you want it.

Basically RSA uses a random key which must be strong, it's best to leave this to be generated by the cryptographic system.  For more "classic" password protection schemes you can use DES (Triple or some other variant) which takes a single encryption key, this key is used to encrypt and decrypt the data (unlike the public key used in RSA to encrypt and the private to decrypt).  The key used by DES must be a "strong" key, i.e. cryptographically strong (so it's not easy to break), the .NET Framework implementation does not allow encryption with weak keys, an exception is thrown.  Normally this key is an array of random bytes.  But by using the PasswordDeriveBytes class you can generate these random bytes from a password string.

The PasswordDeriveBytes constructor takes a password string and some "salt" bytes, these bytes are intermingled in the key generated at (probably) random but calculable locations.  So essentially it takes your password string, converts it to bytes, adds the salt bytes and mixes them up in a particular way, probably based on the values of the password bytes.

So essentially what you need to do is:
  • Generate the public and private key from the RSACryptoServiceProvider.
  • Select a password and use PasswordDeriveBytes to generate a strong DES key.
  • Using DESCryptoServiceProvider encrypt the private key of the RSA Key Pair with the bytes generated in step 2.
  • Do what you want Smile | :)
What I mentioned in the previous reply was that the "salt" bytes must be consistent or calculable from the password string, it's no use using different salt-bytes for the same password string because you won't get the same key so you can't decrypt the private key for the RSA algorithm.

  • The simplest would be to generate some random bytes once and hard-code these into your application as the salt-bytes.  This however is not very secure or wise.
  • The better way to accomplish this would be to write an algorithm (or find one) than generates some random bytes based on the password string, this would mean that the string changes each time the password changes but remains the same for the same password.

Neither of these methods would be very secure since in a) the bytes are hard-coded and easily extractable using Reflector.  In b) they are not so extractable since they are hidden by an algorithm it all depends on how confusing this algorithm is to interpret as to how easy it is to break the system (because once they have the bytes then they can plug them back into the PasswordDeriveBytes class and get your key back).

It's all (as will all cryptography) a matter of complexity verses security.



You know you're a Land Rover owner when the best route from point A to point B is through the mud.

Ed
QuestionGetMembers and COM Pin
dcadenas7-Jun-06 9:00
dcadenas7-Jun-06 9:00 
QuestionUpdate progress bar from a separate project Pin
snorkie7-Jun-06 8:34
professionalsnorkie7-Jun-06 8:34 
AnswerRe: Update progress bar from a separate project Pin
Stefan Troschuetz7-Jun-06 10:01
Stefan Troschuetz7-Jun-06 10:01 
QuestionAborting / Killing Threads Pin
MrEyes7-Jun-06 8:08
MrEyes7-Jun-06 8:08 
AnswerRe: Aborting / Killing Threads Pin
Ed.Poore7-Jun-06 10:45
Ed.Poore7-Jun-06 10:45 
QuestionMDI form child closing [modified] Pin
ak877-Jun-06 6:51
ak877-Jun-06 6:51 
AnswerRe: MDI form child closing [modified] Pin
Josh Smith7-Jun-06 9:16
Josh Smith7-Jun-06 9:16 
QuestionConstraints [modified] Pin
kjosh7-Jun-06 6:48
kjosh7-Jun-06 6:48 
AnswerRe: Constraints Pin
dreynglar8-Jun-06 7:05
dreynglar8-Jun-06 7:05 
QuestionC#/SQL Question Pin
leckey7-Jun-06 6:27
leckey7-Jun-06 6:27 
AnswerRe: C#/SQL Question Pin
NaNg152417-Jun-06 6:50
NaNg152417-Jun-06 6:50 
GeneralRe: C#/SQL Question Pin
Colin Angus Mackay7-Jun-06 8:13
Colin Angus Mackay7-Jun-06 8:13 
AnswerRe: C#/SQL Question Pin
Gerald Schwab7-Jun-06 6:53
Gerald Schwab7-Jun-06 6:53 
GeneralRe: C#/SQL Question Pin
Colin Angus Mackay7-Jun-06 8:14
Colin Angus Mackay7-Jun-06 8:14 
GeneralRe: C#/SQL Question Pin
Gerald Schwab9-Jun-06 7:07
Gerald Schwab9-Jun-06 7:07 
GeneralRe: C#/SQL Question Pin
Colin Angus Mackay9-Jun-06 11:20
Colin Angus Mackay9-Jun-06 11:20 
AnswerRe: C#/SQL Question Pin
malikjhangirahmed@hotmail.com7-Jun-06 7:21
malikjhangirahmed@hotmail.com7-Jun-06 7:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.