public void EncryptDecryptPasswordTest() { string password = "******"; string initialData = "Some text to encrypt"; string cryptData = manager.EncryptPassword(initialData, password); string afterConvert = manager.DecryptPassword(cryptData, password); Assert.AreEqual(initialData, afterConvert); }
public void DecryptPassword_FileDoesNotExist_ThrowsArgumentException() { var fileSystem = new MockFileSystemBuilder().Build(); var passwordDirectory = new MockDirectoryInfo(fileSystem, passwordStorePath); var passwordManager = new PasswordManager(passwordDirectory, new FakeCryptoService(fileSystem), Mock.Of <IRecipientFinder>(), new PasswordFileParser(new UsernameDetectionConfig())); var file = new PasswordFile(fileSystem.FileInfo.FromFileName(@"C:\password-store\password_1"), passwordDirectory); Should.Throw <ArgumentException>(() => passwordManager.DecryptPassword(file, true)); }
public void DecryptPassword_FileExists_DecryptsPassword() { var fileSystem = new MockFileSystemBuilder() .WithFile(@"C:\password-store\password_1", "password\nmetadata") .Build(); var passwordDirectory = new MockDirectoryInfo(fileSystem, passwordStorePath); var passwordManager = new PasswordManager(passwordDirectory, new FakeCryptoService(fileSystem), Mock.Of <IRecipientFinder>(), new PasswordFileParser(new UsernameDetectionConfig())); var file = new PasswordFile(fileSystem.FileInfo.FromFileName(@"C:\password-store\password_1"), passwordDirectory); var decrypted = passwordManager.DecryptPassword(file, true); decrypted.Content.ShouldBe("password\nmetadata"); }
private void Default_Send_Click(object sender, EventArgs e) { if (F_ReportBug_TB_Title.Text == String.Empty || F_ReportBug_TB_Content.Text == String.Empty) { return; } PasswordHasher hasher = new PasswordHasher(); string key = _settings.GetValue("OauthKey"); string secret = _settings.GetValue("OAuthSecret"); if (key == string.Empty || secret == string.Empty) { F_OAuth OAuthEntry = new F_OAuth(_settings); OAuthEntry.ShowDialog(); if (!OAuthEntry.GoodToGO) { return; } key = _settings.GetValue("OauthKey"); secret = _settings.GetValue("OAuthSecret"); } F_Password passwordForm = new F_Password(); passwordForm.ShowDialog(); string realPassword = _settings.GetValue("OAuthPassword"); if (!hasher.CheckPassword(passwordForm.Password, realPassword)) { MessageBox.Show(CentralLanguage.LanguageManager.GetText("Message_Wrong_Password_Text"), CentralLanguage.LanguageManager.GetText("Message_Wrong_Password_Title"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } RepositoryData repository = new RepositoryData("XanatosX", "modulartoolmanager"); PasswordManager pwManager = new PasswordManager(); OAuth authentication = new OAuth(pwManager.DecryptPassword(key, passwordForm.Password), pwManager.DecryptPassword(secret, passwordForm.Password)); if (authentication.ResponseData == null) { return; } Issue issue = new Issue(repository, authentication.ResponseData); HashSet <FileInfo> files = GetFiles(); List <string> uploadFiles = new List <string>(); foreach (FileInfo fi in files) { if (!File.Exists(fi.FullName)) { continue; } uploadFiles.Add(fi.FullName); } string UploadWindowTitle = CentralLanguage.LanguageManager.GetText("Message_Upload_Status_Title"); if (issue.CreateIssue(new IssueCreateData(F_ReportBug_TB_Title.Text, F_ReportBug_TB_Content.Text, _curPriority, _curKind), uploadFiles.ToArray())) { MessageBox.Show(CentralLanguage.LanguageManager.GetText("Message_Upload_Status_Succeded"), UploadWindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } MessageBox.Show(CentralLanguage.LanguageManager.GetText("Message_Upload_Status_Failed"), UploadWindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); }