Namespace: System.Security
Provides types that form the basis of the .NET Framework security model.
The System.Security namespace is a foundational part of the .NET Framework, offering essential types for managing identity, permissions, and cryptography. It allows developers to implement robust security measures within their applications, ensuring secure access to resources and protecting sensitive data.
Key Concepts
- Identity: Represents the security identity of a code or user.
- Permissions: Defines the rights that code has to perform specific security-sensitive operations.
- Cryptography: Provides access to cryptographic services, including hashing, encryption, and digital signatures.
- Principal: Represents the security principal (user or application) that is performing an action.
Classes
Principal Class
Represents the security principal (user or application) that is performing an action.
public abstract class Principal : MarshalByRefObject, System.Security.Principal.IPrincipal
Classes that implement IPrincipal represent the security context of the current thread.
Members:
Identityproperty: Gets the identity of the current principal.IsInRole(string role)method: Determines whether the current principal is in the specified role.
Identity Class
Represents the security identity of a code or user.
public abstract class Identity : MarshalByRefObject, System.Security.Principal.IIdentity
The Identity class is the base class for all identity objects in the .NET Framework security system.
Properties:
Nameproperty: Gets the name of the current identity.AuthenticationTypeproperty: Gets the type of authentication used to determine the name.IsAuthenticatedproperty: Gets a value indicating whether the user has been authenticated.
SecurityIdentifier Class
Represents a security identifier (SID).
public sealed class SecurityIdentifier : System.Security.Principal.IdentityReference
A Security Identifier (SID) is a unique, immutable value used to identify a security principal or security group.
Constructors:
SecurityIdentifier(string sid)SecurityIdentifier(WellKnownSidType sidType, SecurityIdentifier domainSid)
Methods:
Translate(Type targetType)method: Translates the SID to a different representation.IsAccountSid()method: Determines whether the SID represents an account.
Claims Namespace
Contains types related to managing and processing claims, which are assertions of information about a subject.
The System.Security.Claims namespace provides a flexible and standardized way to represent and manage claims, which are key-value pairs that describe a characteristic of a subject, such as a name, role, or group membership.
Key Types:
Claimclass: Represents a single claim.ClaimsIdentityclass: Represents an identity that is defined by a set of claims.ClaimsPrincipalclass: Represents a principal that is defined by a set ofClaimsIdentityobjects.
Cryptography Namespace
Contains cryptographic services, including encryption, decryption, and digital signatures.
The System.Security.Cryptography namespace provides algorithms that can be used to encrypt and decrypt data, sign data to ensure its integrity and authenticity, and hash data to create a secure representation.
Key Classes:
SymmetricAlgorithmclass: Abstract base class for symmetric encryption algorithms.AsymmetricAlgorithmclass: Abstract base class for asymmetric encryption algorithms.HashAlgorithmclass: Abstract base class for hashing algorithms.RSACryptoServiceProviderclass: Implements the RSA algorithm.SHA256Managedclass: Implements the SHA256 hashing algorithm.