Reverse order on close calls on filestream and cryptstream. Change lazy write of cache to 15 seconds from 30 seconds.

This commit is contained in:
Jim Norman 2006-02-01 15:57:13 +00:00
parent 92bfac50fc
commit 2277926029
2 changed files with 41 additions and 31 deletions

View File

@ -92,11 +92,11 @@ namespace sscs.crypto
CSSSLogger.ExpLog(e.ToString()); CSSSLogger.ExpLog(e.ToString());
CSSSLogger.DbgLog("Unable to store the generated key"); CSSSLogger.DbgLog("Unable to store the generated key");
bRet = false; bRet = false;
} }
if (csEncrypt != null)
csEncrypt.Close();
if( fsEncrypt != null ) if( fsEncrypt != null )
fsEncrypt.Close(); fsEncrypt.Close();
if( csEncrypt != null )
csEncrypt.Close();
return bRet; return bRet;
} }
@ -137,9 +137,9 @@ namespace sscs.crypto
{ {
if(storedHash[i] != newHash[i]) if(storedHash[i] != newHash[i])
{ {
CSSSLogger.DbgLog("Hash doesnot match"); CSSSLogger.DbgLog("Hash doesnot match");
fsDecrypt.Close();
csDecrypt.Close(); csDecrypt.Close();
fsDecrypt.Close();
return null; return null;
} }
} }
@ -149,12 +149,16 @@ namespace sscs.crypto
CSSSLogger.ExpLog(e.ToString()); CSSSLogger.ExpLog(e.ToString());
CSSSLogger.DbgLog("Unable to get the stored key"); CSSSLogger.DbgLog("Unable to get the stored key");
baSavedKey = null; baSavedKey = null;
} }
if (csDecrypt != null)
csDecrypt.Close();
if ( fsDecrypt != null ) if ( fsDecrypt != null )
fsDecrypt.Close(); fsDecrypt.Close();
if( csDecrypt != null )
csDecrypt.Close();
return baSavedKey; return baSavedKey;
} }
@ -198,11 +202,11 @@ namespace sscs.crypto
{ {
CSSSLogger.ExpLog(e.ToString()); CSSSLogger.ExpLog(e.ToString());
CSSSLogger.DbgLog("Encrypting and storing to file failed."); CSSSLogger.DbgLog("Encrypting and storing to file failed.");
} }
if (csEncrypt != null)
csEncrypt.Close();
if( fsEncrypt != null ) if( fsEncrypt != null )
fsEncrypt.Close(); fsEncrypt.Close();
if( csEncrypt != null )
csEncrypt.Close();
} }
internal static byte[] ReadFileAndDecryptData(byte[] key, internal static byte[] ReadFileAndDecryptData(byte[] key,
@ -246,29 +250,29 @@ namespace sscs.crypto
{ {
if(storedHash[i] != newHash[i]) if(storedHash[i] != newHash[i])
{ {
CSSSLogger.DbgLog("Hash doesnot match"); CSSSLogger.DbgLog("Hash doesnot match");
fsDecrypt.Close();
csDecrypt.Close(); csDecrypt.Close();
fsDecrypt.Close();
return null; return null;
} }
} }
fsDecrypt.Close();
csDecrypt.Close(); csDecrypt.Close();
fsDecrypt.Close();
return tmpEncrypt; return tmpEncrypt;
} }
catch(Exception e) catch(Exception e)
{ {
Console.WriteLine(e.ToString()); Console.WriteLine(e.ToString());
}
if (csDecrypt != null)
{
csDecrypt.Close();
} }
if( fsDecrypt != null ) if( fsDecrypt != null )
{ {
fsDecrypt.Close(); fsDecrypt.Close();
} }
if( csDecrypt != null )
{
csDecrypt.Close();
}
return null; return null;
} }
@ -394,22 +398,23 @@ namespace sscs.crypto
//Write all data to the crypto stream and flush it. //Write all data to the crypto stream and flush it.
csEncrypt.Write(baMasterPasscode, 0, baMasterPasscode.Length); csEncrypt.Write(baMasterPasscode, 0, baMasterPasscode.Length);
csEncrypt.FlushFinalBlock(); csEncrypt.FlushFinalBlock();
fsEncrypt.Close();
csEncrypt.Close(); csEncrypt.Close();
fsEncrypt.Close();
} }
catch(Exception e) catch(Exception e)
{ {
CSSSLogger.ExpLog(e.ToString()); CSSSLogger.ExpLog(e.ToString());
}
if (csEncrypt != null)
{
csEncrypt.Close();
} }
if( fsEncrypt != null ) if( fsEncrypt != null )
{ {
fsEncrypt.Close(); fsEncrypt.Close();
} }
if( csEncrypt != null )
{
csEncrypt.Close();
}
} }
public static byte[] DecryptMasterPasscodeUsingString(string passwd, public static byte[] DecryptMasterPasscodeUsingString(string passwd,
@ -443,10 +448,15 @@ namespace sscs.crypto
CSSSLogger.DbgLog("Unable to decrypt master passode"); CSSSLogger.DbgLog("Unable to decrypt master passode");
baSavedMasterPasscode = null; baSavedMasterPasscode = null;
} }
if( fsDecrypt != null )
fsDecrypt.Close();
if( csDecrypt != null ) if (csDecrypt != null)
csDecrypt.Close(); csDecrypt.Close();
if ( fsDecrypt != null )
fsDecrypt.Close();
return baSavedMasterPasscode; return baSavedMasterPasscode;
} }

View File

@ -286,7 +286,7 @@ namespace sscs.lss
private void PersistStoreDelayThreadFn() private void PersistStoreDelayThreadFn()
{ {
Thread.Sleep(30000); Thread.Sleep(15000);
PersistStore(); PersistStore();
persistThread = null; persistThread = null;
} }