/// <summary> /// Encrypt a password and write out to a file the display to the user /// </summary> /// <param name="PasswordToEncrypt"></param> private static void WriteEncryptedPassword(String PasswordToEncrypt) { cSimpleAES AES; String EncryptedPassword; String RandomFileName = ""; try { // Create the AES object using the local machine fingerprint and static vector // This is necessary because we want to be able to reuse the encrypted password on the same machine AES = new cSimpleAES(cSecurity.cFingerPrint.Value(), false); // Encrypt the passed value EncryptedPassword = AES.EncryptToString(PasswordToEncrypt); // Get a random file name. Just a little misdirection RandomFileName = System.IO.Path.GetTempFileName(); // Write the password to the file System.IO.File.WriteAllText(RandomFileName, EncryptedPassword); //Run Notepad to show the results to the user so they can copy and paste it. System.Diagnostics.Process.Start("notepad.exe", RandomFileName); } catch (Exception ex) { throw ex; } finally { // Now Delete the file so it can't be picked up by something else. // Do this in the finally routine to guarantee it executes. System.IO.File.Delete(RandomFileName); } }
/// <summary> /// Decrypt an encrypted password /// </summary> /// <param name="Encrypted"></param> /// <returns></returns> private static string DecryptPassword(String EncryptedPassword) { cSimpleAES AES; try { // Create the AES object using the local machine fingerprint and static vector // This is necessary because we want to be able to reuse the encrypted password on the same machine AES = new cSimpleAES(cSecurity.cFingerPrint.Value(), false); // Return the decrypted string return(AES.DecryptString(EncryptedPassword)); } catch (Exception ex) { throw ex; } }