Bug 267542. Creating salt file threw an exception. Changed mode of file creation.

This commit is contained in:
Jim Norman 2007-04-27 15:07:25 +00:00
parent bd7211dbe7
commit ec2cb08082
2 changed files with 32 additions and 29 deletions

View File

@ -531,11 +531,13 @@ namespace sscs.crypto
{ {
if(File.Exists(fileName)) if(File.Exists(fileName))
File.Delete(fileName); File.Delete(fileName);
byte[] baKey = Generate16ByteKeyFromString(passwd, fileName, false, true); byte[] baKey = Generate16ByteKeyFromString(passwd, fileName, false, true);
//Get an encryptor. //Get an encryptor.
RijndaelManaged myRijndael = new RijndaelManaged(); RijndaelManaged myRijndael = new RijndaelManaged();
ICryptoTransform encryptor; ICryptoTransform encryptor;
encryptor = myRijndael.CreateEncryptor(baKey, GenerateAndSaveIV(fileName, myRijndael)); encryptor = myRijndael.CreateEncryptor(baKey, GenerateAndSaveIV(fileName, myRijndael));
//Encrypt the data to a file //Encrypt the data to a file
@ -902,11 +904,8 @@ namespace sscs.crypto
try try
{ {
if (File.Exists(sFileName + ".IV"))
File.Delete(sFileName + ".IV");
// now save this // now save this
FileStream fs = new FileStream(sFileName + ".IV", FileMode.Create); FileStream fs = new FileStream(sFileName + ".IV", FileMode.OpenOrCreate);
fs.Write(baIV, 0, 16); fs.Write(baIV, 0, 16);
fs.Flush(); fs.Flush();
fs.Close(); fs.Close();

View File

@ -58,6 +58,7 @@ using System.IO;
using System.Security.Cryptography; using System.Security.Cryptography;
using sscs.lss; using sscs.lss;
using sscs.common;
namespace sscs.crypto { namespace sscs.crypto {
@ -154,15 +155,18 @@ namespace sscs.crypto {
// save salt // save salt
try try
{ {
FileStream fs = new FileStream(sFilepath + ".salt", FileMode.Create);
FileStream fs = new FileStream(sFilepath + ".salt", FileMode.OpenOrCreate);
fs.Write(randomSalt, 0, randomSalt.Length); fs.Write(randomSalt, 0, randomSalt.Length);
fs.Flush(); fs.Flush();
fs.Close(); fs.Close();
File.SetAttributes(sFilepath + ".salt", FileAttributes.Hidden); File.SetAttributes(sFilepath + ".salt", FileAttributes.Hidden);
} }
catch (Exception e) catch (Exception e)
{ {
CSSSLogger.DbgLog(e.ToString());
} }
return randomSalt; return randomSalt;
@ -181,7 +185,7 @@ namespace sscs.crypto {
} }
catch (Exception e) catch (Exception e)
{ {
CSSSLogger.DbgLog(e.ToString());
} }
return baSalt; return baSalt;
} }