Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Configuration;
- using System.Security.Cryptography;
- using System.Text;
- public class Program
- {
- public static void Main()
- {
- PasswordDigestRequest pdr= new PasswordDigestRequest();
- string wsseHeader = pdr.CreateHeader();
- Console.WriteLine(wsseHeader);
- WebClient wc = new WebClient();
- wc.Headers.Set("Content-Type", "application/xml; charset=UTF-8");
- wc.Headers.Set("cache-control", "no-cache");
- wc.Headers.Set("accept", "application/xml");
- wc.Headers.Set("authorization", "WSSE realm=\"CDP\", profile=\"UsernameToken\"");
- wc.Headers.Set("x-requestheader", "request ServiceId=\"0081022000008125\"");
- wc.Headers.Set("x-wsse", wsseHeader);
- Console.WriteLine(wc.Headers);
- string data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><sms:subscription xmlns:sms=\"urn:oma:xml:rest:sms:1\"> <callbackReference><notifyURL>https://cd45d05c.ngrok.io</notifyURL> <callbackData>123456</callbackData> <notificationFormat>xml</notificationFormat> </callbackReference> <destinationAddress>2404996</destinationAddress> <criteria>sub</criteria> </sms:subscription>";
- string uri = "http://125.60.148.174:8312/1/smsmessaging/inbound/subscriptions";
- string HtmlResult = wc.UploadString(uri, data);
- Console.WriteLine(HtmlResult);
- }
- }
- public class PasswordDigestRequest
- {
- internal string Username { get; set; }
- internal string Password { get; set; }
- internal string Created { get; set; }
- ///
- /// Initializes a new instance of the PasswordDigestRequest class.
- ///
- public PasswordDigestRequest()
- {
- Username = "008102";
- Password = "Vanish123";
- Created = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");
- }
- ///
- /// Creates the header.
- ///
- internal string CreateHeader()
- {
- string nonceStr = GetNonce();
- string hashedPassword = CreateHashedPassword(nonceStr, Created, Password);
- var soapStr = new StringBuilder();
- soapStr.Append("UsernameToken Username=\"");
- soapStr.Append(Username);
- soapStr.Append("\",PasswordDigest=\"");
- soapStr.Append(hashedPassword);
- soapStr.Append("\",Nonce=\"");
- soapStr.Append(nonceStr);
- soapStr.Append("\",Created=\"");
- soapStr.Append(Created);
- soapStr.Append("\"");
- return soapStr.ToString();
- }
- ///
- /// Creates the hashed password.
- ///
- internal static string CreateHashedPassword(string nonce, string created, string password)
- {
- string combinedString = nonce + created + password;
- Console.WriteLine(combinedString);
- //byte[] nonceBytes = Encoding.UTF8.GetBytes(nonce);
- //byte[] createdBytes = Encoding.UTF8.GetBytes(created);
- //byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
- //byte[] combined = new byte[createdBytes.Length + nonceBytes.Length + passwordBytes.Length];
- //Buffer.BlockCopy(nonceBytes, 0, combined, 0, nonceBytes.Length);
- //Buffer.BlockCopy(createdBytes, 0, combined, nonceBytes.Length, createdBytes.Length);
- //Buffer.BlockCopy(passwordBytes, 0, combined, nonceBytes.Length + createdBytes.Length, passwordBytes.Length);
- return Convert.ToBase64String(SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(combinedString)));
- }
- ///
- /// Create a Nonce
- /// returns a random nonce.
- internal static string GetNonce()
- {
- Random rnd = new Random();
- string nonceEnd = rnd.Next(99999).ToString();
- string nonceDate = DateTime.Now.ToString("yyyyMMddHHmmss");
- return nonceDate + nonceEnd;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement