public override byte[] encode()
{
byte[] pkey = null;
byte[] akey = null;
if (_msgFlags.Authentication && _userSecurityModel.EngineId.Length > 0)
{
IAuthenticationDigest auth = Authentication.GetInstance(_userSecurityModel.Authentication);
if (auth == null)
throw new SnmpException(SnmpException.UnsupportedNoAuthPriv, "Invalid authentication protocol.");
akey = auth.PasswordToKey(_userSecurityModel.AuthenticationSecret, _userSecurityModel.EngineId);
if (_msgFlags.Privacy && _userSecurityModel.EngineId.Length > 0)
{
IPrivacyProtocol privacyProtocol = PrivacyProtocol.GetInstance(_userSecurityModel.Privacy);
if (privacyProtocol == null)
throw new SnmpException(SnmpException.UnsupportedPrivacyProtocol, "Specified privacy protocol is not supported.");
pkey = privacyProtocol.PasswordToKey(_userSecurityModel.PrivacySecret, _userSecurityModel.EngineId, auth);
}
}
return encode(akey, pkey);
}