I'm working with a company's Web Service retrieve information, the provide a document with sample code. I have already asked them about the bad code but they insist it works. I have been searching for a solution for days which brings me here.
When I asked what namespace is used for Crypto, they send this link. https://docs.microsoft.com/en-us/dotnet/api/system.web.helpers.crypto?view=aspnet-webpages-3.2
First, Crypto does not have an Encrypt method. Below is the code in their docs and I added a couple error comments. Am I using the correct version of System.Web.Helpers?
public void GetReport(string ApiRequestID, string encryptedUserName)
{
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
Uri address = new Uri("https://someURL");
// Create the web request
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
// Set type to POST
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
StringBuilder data = new StringBuilder();
data.Append("jobNo=" HttpUtility.UrlEncode(ApiRequestID));
//TripleDES.Key = ""
//TripleDES.IV = ""
//Cannot declare a variable of static type System.Web.Helpers.Crypto
Crypto crypto = new Crypto(key, iv);
//System.Web.Helpers.Crypto does not contain a definition for Encrypt and no extension method Encrypt
//accepting a first argument of type 'System.Web.Helpers.Crypto' could be found
//(are you missing a using directive or an assembly reference?)
String encryptedUserName = crypto.Encrypt("MyUserName");
data.Append("&encryptedUserName=" HttpUtility.UrlEncode(encryptedUserName));
// Create a byte array of the data we want to send
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
// Set the content length in the request headers
request.ContentLength = byteData.Length;
ReportInfo info = new ReportInfo();
// Write data
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(LeasingReportInfo));
info = (LeasingReportInfo)ser.ReadObject(response.GetResponseStream());
}
}
Thanks for any input.
CodePudding user response:
