Click here to Skip to main content
15,915,336 members
Home / Discussions / C#
   

C#

 
GeneralDisabling Some items in ComboBox Pin
Osrald29-Aug-04 19:09
Osrald29-Aug-04 19:09 
GeneralRe: Disabling Some items in ComboBox Pin
sreejith ss nair29-Aug-04 22:34
sreejith ss nair29-Aug-04 22:34 
GeneralRe: Disabling Some items in ComboBox Pin
Osrald30-Aug-04 15:12
Osrald30-Aug-04 15:12 
GeneralRe: Disabling Some items in ComboBox Pin
sreejith ss nair30-Aug-04 17:49
sreejith ss nair30-Aug-04 17:49 
GeneralUnable to run two Mysql commands through ODBC in C# Pin
Admiral Ackbar29-Aug-04 14:35
Admiral Ackbar29-Aug-04 14:35 
GeneralRe: Unable to run two Mysql commands through ODBC in C# Pin
Charlie Williams29-Aug-04 16:40
Charlie Williams29-Aug-04 16:40 
GeneralRe: Unable to run two Mysql commands through ODBC in C# Pin
Admiral Ackbar29-Aug-04 17:12
Admiral Ackbar29-Aug-04 17:12 
QuestionCryptography, different decrypt values, why? Pin
Sneha Joseph29-Aug-04 12:22
Sneha Joseph29-Aug-04 12:22 
hi all,
Here's what i'm trying to do:
1.Encrypted User password will be entered into database during Registeration.
2.next time user tries to login i decrpt the value from the data base and allow the user to logon if the decrypted value is same as the User entered password.

My Problem is, no matter what i do i always get different decrpted values for any string.
ie if a user logs on say with a password "letmein" (which is already lying in the database in its encrypted format) when i try to decrypt it back i'm not getting the same value "letmein".
what do i do???
Plz help.
here's my Cryptography Class File.....(could some one tell me whats wrong with my code)

public class Cryptography
{
public static RSACryptoServiceProvider rsa;

public static void AssignParameter()
{
const int PROVIDER_RSA_FULL = 1;
const string CONTAINER_NAME = "MyOnlyContainer";
CspParameters cspParams;
cspParams = new CspParameters(PROVIDER_RSA_FULL);
cspParams.KeyContainerName = CONTAINER_NAME;
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
rsa = new RSACryptoServiceProvider(cspParams);
}

public static string EncryptData(string data2Encrypt)
{
AssignParameter();
StreamReader reader = new StreamReader("PublicOnlyKey.xml");
string publicOnlyKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicOnlyKeyXML);
reader.Close();

//read plaintext, encrypt it to ciphertext
byte[] plainbytes = System.Text.Encoding.UTF8.GetBytes(data2Encrypt);
byte[] cipherbytes = rsa.Encrypt(plainbytes,false);
return Convert.ToBase64String(cipherbytes);
}

public static string DecryptData(string data2Decrypt)
{
AssignParameter();
byte[] getpassword = Convert.FromBase64String(data2Decrypt);
//public and private RSA parameters for encrypt
StreamReader reader = new StreamReader("PublicPrivateKey.xml");
string publicPrivateKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicPrivateKeyXML);
reader.Close();

//read ciphertext, decrypt it to plaintext
byte[] plain = rsa.Decrypt(getpassword,false);
return Convert.ToBase64String(plain);
}

public static void AssignPublicPrivateKeys()
{
AssignParameter();

//provide public and private RSA params
StreamWriter writer = new StreamWriter("PublicPrivateKey.xml");
string publicPrivateKeyXML = rsa.ToXmlString(true);
writer.Write(publicPrivateKeyXML);
writer.Close();

//provide public only RSA params
writer = new StreamWriter("PublicOnlyKey.xml");
string publicOnlyKeyXML = rsa.ToXmlString(false);
writer.Write(publicOnlyKeyXML);
writer.Close();

}


}
please Help Frown | :-(
AnswerRe: Cryptography, different decrypt values, why? Pin
Heath Stewart29-Aug-04 13:14
protectorHeath Stewart29-Aug-04 13:14 
QuestionC# Inherit Base Class Needs Variable - How? Pin
Cyric7429-Aug-04 11:15
Cyric7429-Aug-04 11:15 
AnswerRe: C# Inherit Base Class Needs Variable - How? Pin
S Sansanwal29-Aug-04 11:33
S Sansanwal29-Aug-04 11:33 
GeneralRe: C# Inherit Base Class Needs Variable - How? Pin
Cyric7429-Aug-04 11:39
Cyric7429-Aug-04 11:39 
GeneralRandom number Pin
ImanMahmoud29-Aug-04 10:38
ImanMahmoud29-Aug-04 10:38 
GeneralRe: Random number Pin
Cyric7429-Aug-04 11:33
Cyric7429-Aug-04 11:33 
GeneralRe: Random number Pin
S Sansanwal29-Aug-04 11:33
S Sansanwal29-Aug-04 11:33 
GeneralRe: Random number Pin
ImanMahmoud29-Aug-04 12:27
ImanMahmoud29-Aug-04 12:27 
GeneralRe: Random number Pin
leppie29-Aug-04 12:35
leppie29-Aug-04 12:35 
GeneralGetting the Maximum Possible Size of a control Pin
Waleed Eissa29-Aug-04 7:04
Waleed Eissa29-Aug-04 7:04 
GeneralListBox UserControl Collections Pin
Groovydaz29-Aug-04 3:26
Groovydaz29-Aug-04 3:26 
GeneralRe: ListBox UserControl Collections Pin
Heath Stewart29-Aug-04 11:51
protectorHeath Stewart29-Aug-04 11:51 
Questionhow do my program know that both buttons are down Pin
Umair Ahmad khan28-Aug-04 23:09
Umair Ahmad khan28-Aug-04 23:09 
AnswerRe: how do my program know that both buttons are down Pin
mav.northwind28-Aug-04 23:42
mav.northwind28-Aug-04 23:42 
GeneralRe: how do my program know that both buttons are down Pin
Umair Ahmad khan29-Aug-04 0:57
Umair Ahmad khan29-Aug-04 0:57 
GeneralRe: how do my program know that both buttons are down Pin
Vadim Gusev29-Aug-04 8:02
Vadim Gusev29-Aug-04 8:02 
GeneralRe: how do my program know that both buttons are down Pin
leppie29-Aug-04 8:57
leppie29-Aug-04 8:57 

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.