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"),

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

    Dim x As NetworkCredential = New

    objSmtpClient.Credentials = x

    Catch ex As Exception

    End Try

    objMail.From = objSender

    strMapPath = strServerMapPath

    End Sub

    End Class


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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.