Files
shadowsocks-windows/shadowsocks-csharp/Encryption/EncryptorBase.cs
T
Syrone Wong 1dc992e806 Refine encryption
introduce a constructor to store inner method name

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-09-28 10:46:19 +08:00

63 lines
1.8 KiB
C#

using System.Text;
namespace Shadowsocks.Encryption
{
public struct EncryptorInfo
{
public int KeySize;
public int IvSize;
public int Type;
public string InnerLibName;
// For those who make use of internal crypto method name
// e.g. mbed TLS
public EncryptorInfo(string innerLibName, int keySize, int ivSize, int type)
{
this.KeySize = keySize;
this.IvSize = ivSize;
this.Type = type;
this.InnerLibName = innerLibName;
}
public EncryptorInfo(int keySize, int ivSize, int type)
{
this.KeySize = keySize;
this.IvSize = ivSize;
this.Type = type;
this.InnerLibName = string.Empty;
}
}
public abstract class EncryptorBase
: IEncryptor
{
public const int MAX_INPUT_SIZE = 32768;
protected EncryptorBase(string method, string password, bool onetimeauth, bool isudp)
{
Method = method;
Password = password;
OnetimeAuth = onetimeauth;
IsUDP = isudp;
}
protected string Method;
protected string Password;
protected bool OnetimeAuth;
protected bool IsUDP;
protected byte[] GetPasswordHash()
{
byte[] inputBytes = Encoding.UTF8.GetBytes(Password);
byte[] hash = MbedTLS.MD5(inputBytes);
return hash;
}
public abstract void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
public abstract void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
public abstract void Dispose();
}
}