Could anyone clarify the "whole" story with Rsa-related thing. (I guess, that's because of padding or something).
Ok. My general aim is to encrypt passwords (one way only) to store in database in hashed state.
My approach is:
I create private/public keys with this How to Generate Unique Public and Private Key via RSA (common) approach.
const int PROVIDER_RSA_FULL = 1;
const string CONTAINER_NAME = "KeyContainer";
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);
string publicPrivateKeyXML = rsa.ToXmlString(true);
string publicOnlyKeyXML = rsa.ToXmlString(false);
// do stuff with keys...
and when needed, do this:
var rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(publicOnlyKeyXML);
var valueToEncode = Console.ReadLine();
Console.WriteLine(Convert.ToBase64String(rsa.Encrypt(Encoding.UTF8.GetBytes(valueToEncode), false)));
// initially that's rsa.Encrypt(...
and every new time I do the same value encryption, I receive different values, which is not suitable to store password in such way (as I don't decrypt it for users' authentication, but just compare hashed value).
Could anyone clarify the situation with the encoding stuff?
And also, what are the common practices for passwords encoding to hashes these days (.NET/C#).
Thank you!