Beispiel #1
0
        private void EncryptDataToTest()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var random = new Random();
                for (var i = 0; i < 100; i++)
                {
                    var expected = BuildRandomBytes(random);
                    var nonce    = _localMessageService.CreateNonce();
                    var compress = random.Next(0, 2) == 0;

                    var encrypted = _localMessageService.EncryptDataTo(TestSettings.Account1.PublicKey, expected, nonce, compress, TestSettings.SecretPhrase2);

                    var decrypted = _messageService.DecryptDataFrom(TestSettings.Account2.AccountRs, encrypted, nonce, compress, TestSettings.SecretPhrase1).Result;
                    AssertEquals(expected, decrypted.Data.ToBytes().ToArray(), nameof(decrypted.Data));
                }
            }
        }
        private void SendAlreadyEncryptedMessage()
        {
            using (Logger = new TestsessionLogger(_logger))
            {
                var nonce     = _localMessageService.CreateNonce();
                var encrypted = _localMessageService.EncryptTextTo(TestSettings.Account2.PublicKey, "Hello World!", nonce, true, TestSettings.SecretPhrase1);

                var parameters = CreateTransaction.CreateTransactionByPublicKey(Amount.CreateAmountFromNxt(3));
                parameters.EncryptedMessage = new CreateTransactionParameters.AlreadyEncryptedMessage(encrypted, nonce, true, true);
                var sendMesageResult = _messageService.SendMessage(parameters, TestSettings.Account2.AccountRs).Result;
                var actual           = sendMesageResult.Transaction.EncryptedMessage;

                AssertIsFalse(actual.IsPrunable, nameof(actual.IsPrunable));
                AssertIsTrue(actual.IsCompressed, nameof(actual.IsCompressed));
                AssertIsTrue(actual.IsText, nameof(actual.IsText));
                AssertIsNull(actual.MessageToEncrypt, nameof(actual.MessageToEncrypt));
                AssertIsNull(actual.EncryptedMessageHash, nameof(actual.EncryptedMessageHash));
                AssertEquals(encrypted.ToHexString(), actual.Data.ToHexString(), nameof(actual.Data));
                AssertEquals(nonce.ToHexString(), actual.Nonce.ToHexString(), nameof(actual.Nonce));
            }
        }