/// <summary> /// Decrypts the specified data. /// </summary> /// <param name="data">The data.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public ISnmpData Decrypt(EndPoint sourceEndPoint, ISnmpData data, SecurityParameters parameters) { if (data == null) { throw new ArgumentNullException("data"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } var code = data.TypeCode; if (code != SnmpType.OctetString) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "cannot decrypt the scope data: {0}", code), "data"); } var octets = (OctetString)data; var bytes = octets.GetRaw(); var pkey = AuthenticationProvider.PasswordToKey(_phrase.GetRaw(), parameters.EngineId.GetRaw()); try { // decode encrypted packet var decrypted = Decrypt(bytes, pkey, parameters.PrivacyParameters.GetRaw()); var result = DataFactory.CreateSnmpData(sourceEndPoint, decrypted); if (result.TypeCode != SnmpType.Sequence) { var newException = new DecryptionException("DES decryption failed"); newException.SetBytes(bytes); throw newException; } return(result); } catch (Exception ex) { var newException = new DecryptionException("DES decryption failed", ex); newException.SetBytes(bytes); throw newException; } }
/// <summary> /// Decrypts the specified data. /// </summary> /// <param name="data">The data.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public ISnmpData Decrypt(EndPoint sourceEndPoint, ISnmpData data, SecurityParameters parameters) { if (data == null) { throw new ArgumentNullException("data"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } if (data.TypeCode != SnmpType.Sequence) { var newException = new DecryptionException("Default decryption failed"); throw newException; } return(data); }