/// <summary> /// The Decrypter /// </summary> /// <returns>The <see cref="String"/></returns> public static String Decrypter() { CryptoService cryptoService = new CryptoService(cipherKey); DataPasswordSerializeHolder passData = null; String clearPassword = ""; try { passData = ReadDatFile(); clearPassword = cryptoService.Descrypt(passData.Password, passData.PublicKey); } catch (Exception e) { Console.WriteLine(e.Message); } return(clearPassword); }
/// <summary> /// The ReadDatFile /// </summary> /// <returns>The <see cref="DataPasswordSerializeHolder"/></returns> public static DataPasswordSerializeHolder ReadDatFile() { FileStream fs = new FileStream(EncryptDecrypt.passFilePath, FileMode.Open); DataPasswordSerializeHolder dataPassHolder = null; try { BinaryFormatter formatter = new BinaryFormatter(); dataPassHolder = (DataPasswordSerializeHolder)formatter.Deserialize(fs); } catch (Exception e) { Console.WriteLine(e.Message); } finally { fs.Close(); } return(dataPassHolder); }
/// <summary> /// The WriteDatFile /// </summary> /// <param name="passObject">The passObject<see cref="DataPassword"/></param> public static void WriteDatFile(DataPassword passObject) { FileStream fs = null; try { if (File.Exists(EncryptDecrypt.passFilePath)) { File.Delete(EncryptDecrypt.passFilePath); } fs = File.Create(EncryptDecrypt.passFilePath); DataPasswordSerializeHolder holder = new DataPasswordSerializeHolder(passObject); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fs, holder); } catch (Exception e) { Console.WriteLine(e.Message); } finally { fs.Close(); } }