internal Credential(CREDENTIAL cred) { Flags = cred.Flags; Type = cred.Type; TargetName = cred.TargetName ?? string.Empty; Comment = cred.Comment ?? string.Empty; LastWritten = cred.LastWritten.ToDateTime(); Persist = cred.Persist; TargetAlias = cred.TargetAlias ?? string.Empty; UserName = cred.UserName ?? string.Empty; if (cred.CredentialBlob == IntPtr.Zero || cred.CredentialBlobSize <= 0) { _credblob = new byte[0]; } else { _credblob = new byte[cred.CredentialBlobSize]; Marshal.Copy(cred.CredentialBlob, _credblob, 0, _credblob.Length); } var attrs = new List <CredentialAttribute>(); if (cred.AttributeCount > 0 && cred.Attributes != IntPtr.Zero) { var buffer = new SafeHGlobalBuffer(cred.Attributes, 1, false); attrs.AddRange(buffer.DangerousReadArray <CREDENTIAL_ATTRIBUTE>(0, cred.AttributeCount).Select(a => new CredentialAttribute(a))); } Attributes = attrs.AsReadOnly(); }