NetworkCredential CryptographicException

Discussion in 'ASP .Net Security' started by Marcus Michaels, Jul 21, 2010.

  1. Hi all,

    I am using some old code from a 2.0 project in 4.0, trying to communicate
    with a SMTP-Server. The code works fine in 2.0.

    In 4.0 I receive a CryptographicException (InvalidHandle) when I am trying
    to assign the password to the NetworkCredentials. I tried all constructors,
    assigning the password to the property directly, but no change.

    Underneath please find part of the class and the stack trace.

    Imports System.IO
    Imports System.Net
    Imports System.Net.Mail
    Imports System.Net.Mime
    Imports HtmlAgilityPack
    Imports System.Security

    Public Class MailHelper

    Property objMail As New MailMessage
    Property objSender As MailAddress
    Property objTo As MailAddress
    Property objCC As MailAddress
    Property objBCC As MailAddress
    Property objSmtpClient As SmtpClient
    Property objSmtpCredentials As NetworkCredential

    Property strMapPath As String

    Public Sub New(ByVal strServerMapPath As String)

    objSender = New MailAddress(GetAppSetting("MessageFromEmail"),
    GetAppSetting("MessageFromName"))

    objSmtpClient = New SmtpClient(GetAppSetting("SmtpServer"))
    objSmtpClient.UseDefaultCredentials = False

    Try
    Dim x As NetworkCredential = New
    System.Net.NetworkCredential("a","b")

    objSmtpClient.Credentials = x

    Catch ex As Exception

    End Try

    objMail.From = objSender

    strMapPath = strServerMapPath

    End Sub

    End Class


    STACK TRACE:

    bei System.Security.SecureString.ProtectMemory()
    bei System.Security.SecureString.InitializeSecureString(Char* value,
    Int32 length)
    bei System.Security.SecureString..ctor(Char* value, Int32 length)
    bei
    System.Net.UnsafeNclNativeMethods.SecureStringHelper.CreateSecureString(String plainString)
    bei System.Net.NetworkCredential..ctor(String userName, String password)
     
    Marcus Michaels, Jul 21, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dei401
    Replies:
    0
    Views:
    785
    Dei401
    Feb 2, 2005
  2. =?Utf-8?B?ZnJlcXVuZW5jeQ==?=

    CryptographicException Bad Data in Windo

    =?Utf-8?B?ZnJlcXVuZW5jeQ==?=, Jul 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    616
    =?Utf-8?B?ZnJlcXVuZW5jeQ==?=
    Jul 20, 2005
  3. muthu
    Replies:
    1
    Views:
    530
    Winista
    Jul 10, 2006
  4. Brad
    Replies:
    1
    Views:
    1,701
    Steven Cheng[MSFT]
    Aug 30, 2006
  5. Brent K
    Replies:
    2
    Views:
    652
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jul 12, 2007
Loading...

Share This Page