public void DerivedKeys_Should_ProduceTheSameKeyProvidedWithSamePassword() { // Arrange var vector = new EncryptionData("sdfasdfasdfasdf"); var k1 = new DerivedKey(_password); var ek1 = new EncryptionData(k1.GetBytes(25)); var k2 = new DerivedKey(_password); var ek2 = new EncryptionData(k2.GetBytes(25)); var e1 = new SymmetricEncryption(SymmetricEncryption.Provider.TripleDES) { InitializationVector = vector }; var e2 = new SymmetricEncryption(SymmetricEncryption.Provider.TripleDES) { InitializationVector = vector }; // Act var encrypted = e1.Encrypt(new EncryptionData(_plainText), ek1); var decrypted = e2.Decrypt(encrypted, ek2); // Assert Assert.Equal(_plainText, decrypted.Text); }
protected override async Task Submit(ButtonRow button) { IsBusy = true; var password = _password?.Edit?.Text; if (!WalletApp.IsCoreAccountUnlocked) { if (!await WalletApp.UnlockCoreAccount(password)) { await ErrorAsync("PasswordWrong"); IsBusy = false; return; } } var chainId = int.Parse(_chainIdText.Edit.Text); var coreAccount = WalletApp.CurrentCoreAccount; var secretKey = await PassphraseSecretKeyInfo.NewPassphraseSecretKey(chainId, $"{Hex.ToString(coreAccount.RawData)}.{coreAccount.AccountId}"); var key = await Task.Run(() => Key.GenerateEd25519(secretKey.SecretHash)); var encryption = await Task.Run(() => Encryption.GenerateAes256(key.Data, _derivedPassword)); _keyView.Update(key); if (!await ConfirmAsync("AuthorizeConfirm")) { IsBusy = false; return; } (var response, var publicKey) = await WalletApp.JoinChain(chainId, 0, key.PublicKey, password); if (response.TransactionResult == TransactionResultTypes.Ok || response.TransactionResult == TransactionResultTypes.AlreadyJoined) { var derivedKey = new DerivedKey(coreAccount.AccountId, chainId, publicKey.KeyIndex, encryption); var hex = Hex.ToCrcString(derivedKey.ToByteArray()); _export.Edit.Text = hex; UIApp.CopyToClipboard(hex); await MessageAsync("SuccessDerived"); } else { await ErrorTextAsync(response.GetErrorMessage()); } IsBusy = false; }
public override int GetHashCode() { return(DerivedKey.GetHashCode()); }
public void HashPassword_returns_hashed_password() { var hash = Util.HashPassword(Password, DerivedKey.Decode64()); Assert.Equal(PasswordHash.Decode64(), hash); }
public void DeriveKey_trims_whitespace_and_lowercases_username() { var key = Util.DeriveKey(" UsErNaMe ", Password, 100); Assert.Equal(DerivedKey.Decode64(), key); }
public void DeriveKey_returns_derived_key() { var key = Util.DeriveKey(Username, Password, 100); Assert.Equal(DerivedKey.Decode64(), key); }