namespace AsiaINFO.SMS.CMPP2
|
{
|
using System;
|
using System.Security.Cryptography;
|
using System.Text;
|
|
public class CMPP_CONNECT
|
{
|
private byte[] _AuthenticatorSource;
|
private MessageHeader _Header;
|
private string _Password;
|
private string _Source_Addr;
|
private uint _Timestamp;
|
private uint _Version;
|
public const int BodyLength = 0x1b;
|
|
public CMPP_CONNECT(string Source_Addr, string Password, DateTime Timestamp, uint Version, uint Sequence_Id)
|
{
|
this._Header = new MessageHeader(0x27, CMPP_Command_Id.CMPP_CONNECT, Sequence_Id);
|
this._Source_Addr = Source_Addr;
|
this._Password = Password;
|
string s = Util.Get_MMDDHHMMSS_String(Timestamp);
|
this._Timestamp = uint.Parse(s);
|
byte[] bytes = Encoding.ASCII.GetBytes(Source_Addr);
|
byte[] sourceArray = Encoding.ASCII.GetBytes(Password);
|
byte[] buffer3 = Encoding.ASCII.GetBytes(s);
|
byte[] destinationArray = new byte[((bytes.Length + 9) + sourceArray.Length) + buffer3.Length];
|
Array.Copy(bytes, destinationArray, bytes.Length);
|
Array.Copy(sourceArray, 0, destinationArray, bytes.Length + 9, sourceArray.Length);
|
Array.Copy(buffer3, 0, destinationArray, (bytes.Length + 9) + sourceArray.Length, buffer3.Length);
|
this._AuthenticatorSource = new MD5CryptoServiceProvider().ComputeHash(destinationArray);
|
this._Version = Version;
|
}
|
|
public byte[] ToBytes()
|
{
|
int dstOffset = 0;
|
byte[] dst = new byte[0x27];
|
byte[] src = this._Header.ToBytes();
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 12;
|
src = Encoding.ASCII.GetBytes(this._Source_Addr);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 6;
|
src = this._AuthenticatorSource;
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 0x10;
|
dst[dstOffset++] = (byte) this._Version;
|
src = BitConverter.GetBytes(this._Timestamp);
|
Array.Reverse(src);
|
src.CopyTo(dst, dstOffset);
|
return dst;
|
}
|
|
public override string ToString()
|
{
|
return string.Format("Header={0} AuthenticatorSource={1} Password={2} Source_Addr={3} Timestamp={4} Version={5}", new object[] { this._Header.ToString(), this._AuthenticatorSource, this._Password, this._Source_Addr, this._Timestamp, this._Version });
|
}
|
|
public byte[] AuthenticatorSource
|
{
|
get
|
{
|
return this._AuthenticatorSource;
|
}
|
}
|
|
public MessageHeader Header
|
{
|
get
|
{
|
return this._Header;
|
}
|
}
|
}
|
}
|