---
title: "Role base security and cryptography in .net"  
description: "In this blog, I’m explaining about Role base security and cryptography in .NET    Role Base security in .NET1.Use forms authentication to obtain and v"  
author: "priyanka kushwaha"  
published: 2015-02-27  
updated: 2018-02-22  
canonical: https://www.mindstick.com/blog/803/role-base-security-and-cryptography-in-dot-net  
category: ".net"  
tags: ["security", "cryptography"]  
reading_time: 2 minutes  

---

# Role base security and cryptography in .net

##### In this blog, I’m explaining about Role base security and cryptography in .NET\

##### \

##### Role Base security in .NET

##

1. Use [forms authentication](https://www.mindstick.com/forum/311/forms-authentication-and-authorization) to obtain and [validate user](https://www.mindstick.com/forum/157975/how-can-use-jquery-s-form-validation-plugin-to-validate-user-input-and-provide-feedback-to-users) credentials.

2. Create forms [Authentication Ticket](https://www.mindstick.com/interview/34194/how-can-you-create-and-manually-set-a-custom-forms-authentication-ticket) objects based on name and roles retrieved from the data store.

3. User Generic principle class that provides the roles-based authorization checking functionality. ASP.NET requires it to be stored in the HttpContext. User to relate it current [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) Http request.

4. Use these objects to make authorization decisions.

5. .NET [Framework](https://www.mindstick.com/forum/34615/software-framework-vs-library) provides support for the [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) of role-based security which consists of Authentication (identity) and Authorization (rights).

6. The .NET provides access to the user through an identity and authorization access by the principal object.

7. Identities correspond to users and their properties.identity classes belong to system.security.principal Namespace.

8. Roles are the string of role names added to a Principal to associate the [current user](https://www.mindstick.com/forum/34471/get-current-user-id-in-mvc) with his assigned roles.

##### \

##### Cryptography

##

[Cryptography](https://www.mindstick.com/articles/332994/exploring-the-significance-of-cryptography-in-network-security) is a method used to protect the information and data from other parties that might use that data for any illegal activity.

ASP.NET provides a new class as Crypto present in System.Web.Helpers namespace.

##### \

##### Using the Crypto Class

##

The Crypto class contain the simplified versions of the cryptography.

The class is a static class, which means you cannot create an instance of this class.

##### \

## Using the Method

## \

## 1. String GeneratingSalt()

This method generates a new Salt to be added to the [input string](https://www.mindstick.com/forum/72/input-string-was-not-in-a-correct-format) before the hashing process would start.

\

## 2. String Hash()

This function hashes the input string using either the default (SHA-256) algorithm or the user can pass algorithm for the ASP.NET to use to hash the password into.

\

## 3. String HashPassword()

This function returns an RFC 2898 hash value of the input string passed by the user.

\

## 4. Sting SHA1

Return the SHA1 hashed value for the input string provided.

\

## 5. String SHA256

The algorithm used is SHA-256

\

## 6. Bool VerifyHashPassword

This method would check for the password sent by the user.

---

Original Source: https://www.mindstick.com/blog/803/role-base-security-and-cryptography-in-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
