public static string SignData(string data, string privateKeyPath = "private-key.xml")
        {
            var privateKey = RsaKeyLoader.FromXmlFile(privateKeyPath);
            var signature  = privateKey.SignData(PaymentHandler.DigestEncoding.GetBytes(data),
                                                 PaymentHandler.HashAlgorithm,
                                                 PaymentHandler.SignaturePadding);

            return(Convert.ToBase64String(signature));
        }
        public static async Task <string> SendRequest(
            string accountKey,
            PaymentHandler.Gateway gateway,
            string payloadPath    = "payload.xml",
            string privateKeyPath = "private-key.xml",
            string hostname       = "paymentapi.contact-world.net")
        {
            var payload    = File.ReadAllText(payloadPath).Trim();
            var privateKey = RsaKeyLoader.FromXmlFile(privateKeyPath);
            var handler    = new PaymentHandler(accountKey, gateway, hostname, privateKey, TimeSpan.FromSeconds(1));

            return(await handler.MakePayment(payload, Console.WriteLine));
        }
        public static bool VerifySignature(string signatureBase64,
                                           string data,
                                           string publicKeyPath = "public-key.xml")
        {
            var publicKey = RsaKeyLoader.FromXmlFile(publicKeyPath);
            var signature = Convert.FromBase64String(signatureBase64);
            var dataBytes = PaymentHandler.DigestEncoding.GetBytes(data);

            return(publicKey.VerifyData(dataBytes,
                                        signature,
                                        PaymentHandler.HashAlgorithm,
                                        PaymentHandler.SignaturePadding));
        }
        public static bool CheckKeys(
            string privateKeyPath = "private-key.xml",
            string publicKeyPath  = "public-key.xml")
        {
            var privateKey = RsaKeyLoader.FromXmlFile(privateKeyPath);
            var publicKey  = RsaKeyLoader.FromXmlFile(publicKeyPath);
            var testData   = PaymentHandler.DigestEncoding.GetBytes("NewVoiceMedia Rulezzz");
            var signature  = privateKey.SignData(testData,
                                                 PaymentHandler.HashAlgorithm,
                                                 PaymentHandler.SignaturePadding);

            return(publicKey.VerifyData(testData,
                                        signature,
                                        PaymentHandler.HashAlgorithm,
                                        PaymentHandler.SignaturePadding));
        }
        public static async Task <string> RelayRequest(
            string accountKey,
            PaymentHandler.Gateway gateway,
            string privateKeyPath = "private-key.xml",
            string hostname       = "paymentapi.contact-world.net")
        {
            var    payload = new StringBuilder();
            string line;

            while ((line = Console.ReadLine()) != null)
            {
                payload.AppendLine(line);
            }
            var privateKey = RsaKeyLoader.FromXmlFile(privateKeyPath);
            var handler    = new PaymentHandler(accountKey, gateway, hostname, privateKey, TimeSpan.FromSeconds(1));

            return(await handler.MakePayment(payload.ToString(), Console.WriteLine));
        }