public void XmlWithoutRSAKeyValueThrowsException()
        {
            const string InvalidXml = "<Banana>Hello World</Banana>";

            Assert.That(() => RsaParametersExtensions.FromXmlString(InvalidXml),
                        Throws.TypeOf <CryptographicException>());
        }
        public void PublicRsaParametersToString()
        {
            var expectedRsaParameters =
                RsaParametersExtensions.FromXmlString(TestData.ClientPublicRsaXml);
            string xmlString     = expectedRsaParameters.ToXmlString();
            var    rsaParameters = RsaParametersExtensions.FromXmlString(xmlString);

            AssertRsaParametersAreEqual(rsaParameters, expectedRsaParameters);
        }
Esempio n. 3
0
        private async void OnClickBalanceButton(object sender, EventArgs e)
        {
            var balanceLabel = FindViewById <TextView>(Resource.Id.balanceLabel);
            var privateApi   = new FairlayPrivateApiBuilder(new PrivateApiCredentials(1004056)
            {
                PrivateRsaParameters = RsaParametersExtensions.FromXmlString(ClientPrivateRsaXml)
            }).Build();
            var balances = await privateApi.GetBalances();

            balanceLabel.Text = "TestAccount Balance: " + balances[0].AvailableFunds + " mBTC";
        }
 public void EncryptAndDecryptDataWithImportedRsaParameters()
 {
     using (var rsa = RSA.Create())
     {
         var rsaParameters = RsaParametersExtensions.FromXmlString(TestData.ClientPrivateRsaXml);
         rsa.ImportParameters(rsaParameters);
         var originalData  = Encoding.UTF8.GetBytes("Hello World");
         var encryptedData = rsa.Encrypt(originalData, RSAEncryptionPadding.Pkcs1);
         var decryptedData = rsa.Decrypt(encryptedData, RSAEncryptionPadding.Pkcs1);
         Assert.That(decryptedData, Is.EqualTo(originalData));
     }
 }
Esempio n. 5
0
        private static async Task UsePrivateApi()
        {
            var privateApi = new FairlayPrivateApiBuilder(new PrivateApiCredentials(1004056)
            {
                PrivateRsaParameters = RsaParametersExtensions.FromXmlString(ClientPrivateRsaXml)
            }).Build();
            var balances = await privateApi.GetBalances();

            Console.WriteLine("Your current available balance: " +
                              balances[CurrencyIds.Mbtc].AvailableFunds.ToCoinString());
            Console.WriteLine("Your balances details: " + JsonConvert.SerializeObject(balances));
            var statements = await privateApi.GetStatement(DateTime.UtcNow.AddMonths(-1));

            Console.WriteLine("Your statements of the past month are: " +
                              JsonConvert.SerializeObject(statements));
        }