/// <summary> /// The Encrypter /// </summary> /// <param name="passText">The passText<see cref="String"/></param> public static void Encrypter(String passText) { CryptoService cryptoService = new CryptoService(cipherKey); passData = cryptoService.Encrypt(passText); WriteDatFile(passData); }
/// <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 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(); } }