public static void WriteBin(byte[] _storage, string _saveAsUniqueId, string _fileDir) { //Write to wallet file String FileFolder = _fileDir + CandyStore.GetParameters().FileFolder; String FilePath = FileFolder + _saveAsUniqueId + ".bin"; if (!Directory.Exists(FileFolder)) { //Create directory if it does not exist Directory.CreateDirectory(FileFolder); } BinaryWriter writer = new BinaryWriter(File.Open(FilePath, FileMode.Create)); writer.Write(_storage); //Write binaries writer.Close(); }
public static PassObject ReadBlobToObject(string _readAsUniqueId, string _fileDir) { //Read from bin string filePath = _fileDir + CandyStore.GetParameters().FileFolder + _readAsUniqueId + ".bin"; if (!File.Exists(filePath)) { throw new Exception("Filepath does not exist"); } byte[] BlobData = ReadBin(filePath); MemoryStream memorystreamd = new MemoryStream(BlobData); BinaryFormatter bfd = new BinaryFormatter(); PassObject deserializedobject = bfd.Deserialize(memorystreamd) as PassObject; memorystreamd.Close(); return(deserializedobject); }
public static string RemoveStorageSpecific(string _fileDir, string _websiteUniqueID) { //Write to wallet file string filePath = _fileDir + CandyStore.GetParameters().FileFolder + _websiteUniqueID + ".bin"; if (!File.Exists(filePath)) { throw new Exception("File does not exist"); } //Delete storage folder try { File.Delete(filePath); return("Removal completed"); } catch { return("Removal failed"); } }
public static Boolean CreatePass(string _websiteString, string _websitePass, string _encryptionKey, string _fileDir, int _numOfIterations) { string uniqueId = CandyStore.PBKDF2Service(_websiteString, _numOfIterations); uniqueId = CandyStore.ToHexString(uniqueId); string encryptedPass = EncryptDecryptStore.Encrypt(_websitePass, _encryptionKey); PassObject passObject = new PassObject(); //Create new instance of PassObject try { passObject.SetUniqueId(uniqueId); passObject.SetEncryptedPass(encryptedPass); StorageHelper.WriteObjectToBlob(passObject, uniqueId, _fileDir); //Store object return(true); } catch { return(false); } }