public async Task TestSimpleCreateAsymmetricKeysStore() { FakeDataStore.AddFolder(@"C:\Temp"); IDataContainer workFolder = New <IDataContainer>(@"C:\Temp"); AccountStorage store = new AccountStorage(new LocalAccountService(new LogOnIdentity(EmailAddress.Parse(@"*****@*****.**"), new Passphrase("secret")), workFolder)); UserKeyPair userKeyPair = new UserKeyPair(EmailAddress.Parse("*****@*****.**"), 512); await store.ImportAsync(userKeyPair); Assert.That((await store.AllKeyPairsAsync()).First().KeyPair.PrivateKey, Is.Not.Null); Assert.That((await store.AllKeyPairsAsync()).First().KeyPair.PublicKey, Is.Not.Null); }
private async static Task <LogOnIdentity> LogOnIdentityFromUserAsync(EmailAddress emailAddress, Passphrase passphrase) { AccountStorage store = new AccountStorage(New <LogOnIdentity, IAccountService>(new LogOnIdentity(emailAddress, passphrase))); if (await store.IsIdentityValidAsync()) { return(new LogOnIdentity(await store.AllKeyPairsAsync(), passphrase)); } return(LogOnIdentity.Empty); }
public async Task TestEncryptCreateLoadDecryptWithAsymmetricKeysStore() { FakeDataStore.AddFolder(@"C:\Temp"); IDataContainer workFolder = New <IDataContainer>(@"C:\Temp\"); AccountStorage store = new AccountStorage(new LocalAccountService(new LogOnIdentity(EmailAddress.Parse(@"*****@*****.**"), new Passphrase("secret")), workFolder)); await Resolve.KnownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("secret")); UserKeyPair userKeyPair = new UserKeyPair(EmailAddress.Parse("*****@*****.**"), 512); await store.ImportAsync(userKeyPair); string text = "AxCrypt encryption rules!"; byte[] encryptedBytes = (await store.AllKeyPairsAsync()).First().KeyPair.PublicKey.Transform(Encoding.UTF8.GetBytes(text)); store = new AccountStorage(new LocalAccountService(new LogOnIdentity(EmailAddress.Parse(@"*****@*****.**"), new Passphrase("secret")), workFolder)); byte[] decryptedBytes = (await store.AllKeyPairsAsync()).First().KeyPair.PrivateKey.Transform(encryptedBytes); Assert.That(decryptedBytes != null); string decryptedText = Encoding.UTF8.GetString(decryptedBytes); Assert.That(text, Is.EqualTo(decryptedText)); }
private async Task ImportFileActionAsync() { IDataStore privateKeyData = New <IDataStore>(PrivateKeyFileName); Passphrase passphrase = new Passphrase(PasswordText); UserKeyPair keyPair; if (!UserKeyPair.TryLoad(privateKeyData.ToArray(), passphrase, out keyPair)) { ImportSuccessful = false; return; } LogOnIdentity identity = new LogOnIdentity(keyPair.UserEmail, passphrase); AccountStorage store = new AccountStorage(New <LogOnIdentity, IAccountService>(identity)); await store.ImportAsync(keyPair); ImportSuccessful = true; _userSettings.UserEmail = keyPair.UserEmail.Address; await _knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity(await store.AllKeyPairsAsync(), passphrase)); }
private async Task InitializePropertyValuesAsync() { AccountProperties = (await _accountStorage.AllKeyPairsAsync()).Select(key => new AccountProperties(key.UserEmail, key.Timestamp)); ChangePassphraseAsync = new AsyncDelegateAction <string>(async(password) => await ChangePassphraseActionAsync(password), async(password) => (await _accountStorage.AllKeyPairsAsync()).Any()); }