//Password authentication similar to github python code
var nonce = res_text.Split(' ')[1];
var cnonce_text = $"{file_uri}{content_size}{file_md5}{remoteAddr}";
var cnonce = cnonce_text.ToMD5Hash();
var passmd5 = password.ToMD5Hash();
var result_text = $"{passmd5}:{nonce}:{cnonce}";
var result = result_text.ToMD5Hash();
Console.WriteLine("Authenticating...");
message = $"{FLASH_Options.AUTH:D} {cnonce} {result}\n";
message_bytes = message.Encode();
//Send authentication request
sock2.Send(message_bytes, message_bytes.Length, ep);
t = sock2.ReceiveAsync();
public static byte[] Encode(this string @this)
{
return Encoding.ASCII.GetBytes(@this);
}
/// <summary>
/// A Stream extension method that converts the @this to a md 5 hash.
/// </summary>
/// <param name="this">The @this to act on.</param>
/// <returns>@this as a string.</returns>
public static string ToMD5Hash(this Stream @this)
{
using (MD5 md5 = MD5.Create())
{
byte[] hashBytes = md5.ComputeHash(@this);
var sb = new StringBuilder();
foreach (byte bytes in hashBytes)
{
sb.Append(bytes.ToString("x2"));
}
return sb.ToString();
}
}
/// <summary>
/// A Stream extension method that converts the @this to a md 5 hash.
/// </summary>
/// <param name="this">The @this to act on.</param>
/// <returns>@this as a string.</returns>
public static string ToMD5Hash(this string @this, bool useACII=false)
{
using (MD5 md5 = MD5.Create())
{
byte[] hashBytes = md5.ComputeHash(useACII ? Encoding.ASCII.GetBytes(@this) : Encoding.UTF8.GetBytes(@this));
var sb = new StringBuilder();
foreach (byte bytes in hashBytes)
{
sb.Append(bytes.ToString("x2"));
}
return sb.ToString();
}
}