Changes to make ProtectedData.Protect() and ProtectedData.Unprotect() use entropy.

This commit is contained in:
Rajasekaran Nagarajan 2006-12-19 23:21:24 +00:00
parent 8b6a60e9ab
commit 98c12387a6

View File

@ -678,7 +678,7 @@ namespace sscs.crypto
fs.Close();
baSavedMasterPasscode = new byte[16];
baSavedMasterPasscode = ProtectedData.Unprotect( encryptedMasterPasscode, null, DataProtectionScope.CurrentUser );
baSavedMasterPasscode = ProtectedData.Unprotect( encryptedMasterPasscode, RetrieveIV(fileName, new byte[16]), DataProtectionScope.CurrentUser );
}
catch (CryptographicException e)
{
@ -740,7 +740,7 @@ namespace sscs.crypto
myRijndael.GenerateKey();
baPasscode = myRijndael.Key;
byte [] encryptedMasterPasscode = ProtectedData.Protect( baPasscode, null, DataProtectionScope.CurrentUser );
byte [] encryptedMasterPasscode = ProtectedData.Protect( baPasscode, GenerateAndSaveIV(fileName, null), DataProtectionScope.CurrentUser );
FileStream fs = new FileStream(fileName, FileMode.Create);
File.SetAttributes(fileName, FileAttributes.Hidden);
fs.Write(encryptedMasterPasscode, 0, encryptedMasterPasscode.Length);
@ -801,8 +801,18 @@ namespace sscs.crypto
private static byte[] GenerateAndSaveIV(string sFileName, RijndaelManaged theRiManaged)
{
theRiManaged.GenerateIV();
byte[] baIV = theRiManaged.IV;
byte[] baIV = null;
if ( theRiManaged != null )
{
theRiManaged.GenerateIV();
baIV = theRiManaged.IV;
}
else
{
RandomNumberGenerator rng = RandomNumberGenerator.Create ();
baIV = new byte [16];
rng.GetBytes (baIV);
}
try
{