Bug 267542. Creating salt file threw an exception. Changed mode of file creation.
This commit is contained in:
parent
bd7211dbe7
commit
ec2cb08082
@ -291,18 +291,18 @@ namespace sscs.crypto
|
||||
{
|
||||
|
||||
FileStream fsHash = null;
|
||||
byte[] hash = null;
|
||||
byte[] hash = null;
|
||||
|
||||
try
|
||||
{
|
||||
SHA256 shaM = new SHA256Managed();
|
||||
hash = shaM.ComputeHash(baPasscode);
|
||||
SHA256 shaM = new SHA256Managed();
|
||||
hash = shaM.ComputeHash(baPasscode);
|
||||
|
||||
fsHash = new FileStream(fileName, FileMode.Create);
|
||||
File.SetAttributes(fileName, FileAttributes.Hidden);
|
||||
fsHash = new FileStream(fileName, FileMode.Create);
|
||||
File.SetAttributes(fileName, FileAttributes.Hidden);
|
||||
|
||||
fsHash.Write(hash, 0, hash.Length);
|
||||
fsHash.Flush();
|
||||
fsHash.Write(hash, 0, hash.Length);
|
||||
fsHash.Flush();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@ -530,15 +530,17 @@ namespace sscs.crypto
|
||||
try
|
||||
{
|
||||
if(File.Exists(fileName))
|
||||
File.Delete(fileName);
|
||||
File.Delete(fileName);
|
||||
|
||||
byte[] baKey = Generate16ByteKeyFromString(passwd, fileName, false, true);
|
||||
|
||||
//Get an encryptor.
|
||||
RijndaelManaged myRijndael = new RijndaelManaged();
|
||||
ICryptoTransform encryptor;
|
||||
ICryptoTransform encryptor;
|
||||
|
||||
encryptor = myRijndael.CreateEncryptor(baKey, GenerateAndSaveIV(fileName, myRijndael));
|
||||
|
||||
//Encrypt the data to a file
|
||||
//Encrypt the data to a file
|
||||
fsEncrypt = new FileStream(fileName,FileMode.Create);
|
||||
|
||||
csEncrypt = new CryptoStream(fsEncrypt, encryptor,
|
||||
@ -888,25 +890,22 @@ namespace sscs.crypto
|
||||
private static byte[] GenerateAndSaveIV(string sFileName, RijndaelManaged theRiManaged)
|
||||
{
|
||||
byte[] baIV = null;
|
||||
if ( theRiManaged != null )
|
||||
{
|
||||
theRiManaged.GenerateIV();
|
||||
baIV = theRiManaged.IV;
|
||||
}
|
||||
else
|
||||
{
|
||||
RandomNumberGenerator rng = RandomNumberGenerator.Create ();
|
||||
baIV = new byte [16];
|
||||
rng.GetBytes (baIV);
|
||||
}
|
||||
if ( theRiManaged != null )
|
||||
{
|
||||
theRiManaged.GenerateIV();
|
||||
baIV = theRiManaged.IV;
|
||||
}
|
||||
else
|
||||
{
|
||||
RandomNumberGenerator rng = RandomNumberGenerator.Create ();
|
||||
baIV = new byte [16];
|
||||
rng.GetBytes (baIV);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (File.Exists(sFileName + ".IV"))
|
||||
File.Delete(sFileName + ".IV");
|
||||
|
||||
// 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.Flush();
|
||||
fs.Close();
|
||||
|
@ -58,6 +58,7 @@ using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using sscs.lss;
|
||||
using sscs.common;
|
||||
|
||||
namespace sscs.crypto {
|
||||
|
||||
@ -154,15 +155,18 @@ namespace sscs.crypto {
|
||||
// save salt
|
||||
try
|
||||
{
|
||||
FileStream fs = new FileStream(sFilepath + ".salt", FileMode.Create);
|
||||
|
||||
FileStream fs = new FileStream(sFilepath + ".salt", FileMode.OpenOrCreate);
|
||||
fs.Write(randomSalt, 0, randomSalt.Length);
|
||||
fs.Flush();
|
||||
fs.Close();
|
||||
fs.Close();
|
||||
|
||||
File.SetAttributes(sFilepath + ".salt", FileAttributes.Hidden);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
CSSSLogger.DbgLog(e.ToString());
|
||||
}
|
||||
|
||||
return randomSalt;
|
||||
@ -181,7 +185,7 @@ namespace sscs.crypto {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
CSSSLogger.DbgLog(e.ToString());
|
||||
}
|
||||
return baSalt;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user