725 lines
28 KiB
HTML
725 lines
28 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Class SecurityHelper | CapyKit Documentation </title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="title" content="Class SecurityHelper | CapyKit Documentation ">
|
|
|
|
<meta name="description" content="A class that contains methods for managing secure data processing and cryptography.">
|
|
<link rel="icon" href="../favicon.ico">
|
|
<link rel="stylesheet" href="../public/docfx.min.css">
|
|
<link rel="stylesheet" href="../public/main.css">
|
|
<meta name="docfx:navrel" content="../toc.html">
|
|
<meta name="docfx:tocrel" content="toc.html">
|
|
|
|
<meta name="docfx:rel" content="../">
|
|
|
|
|
|
|
|
<meta name="loc:inThisArticle" content="In this article">
|
|
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
|
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
|
<meta name="loc:tocFilter" content="Filter by title">
|
|
<meta name="loc:nextArticle" content="Next">
|
|
<meta name="loc:prevArticle" content="Previous">
|
|
<meta name="loc:themeLight" content="Light">
|
|
<meta name="loc:themeDark" content="Dark">
|
|
<meta name="loc:themeAuto" content="Auto">
|
|
<meta name="loc:changeTheme" content="Change theme">
|
|
<meta name="loc:copy" content="Copy">
|
|
<meta name="loc:downloadPdf" content="Download PDF">
|
|
|
|
<script type="module" src="./../public/docfx.min.js"></script>
|
|
|
|
<script>
|
|
const theme = localStorage.getItem('theme') || 'auto'
|
|
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
|
|
<header class="bg-body border-bottom">
|
|
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
|
<div class="container-xxl flex-nowrap">
|
|
<a class="navbar-brand" href="../index.html">
|
|
<img id="logo" class="svg" src="../logo.svg" alt="CapyKit Documentation">
|
|
CapyKit Documentation
|
|
</a>
|
|
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
|
<i class="bi bi-three-dots"></i>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navpanel">
|
|
<div id="navbar">
|
|
<form class="search" role="search" id="search">
|
|
<i class="bi bi-search"></i>
|
|
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="container-xxl">
|
|
<div class="toc-offcanvas">
|
|
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
|
<div class="offcanvas-header">
|
|
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
|
</div>
|
|
<div class="offcanvas-body">
|
|
<nav class="toc" id="toc"></nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<div class="actionbar">
|
|
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
|
<i class="bi bi-list"></i>
|
|
</button>
|
|
|
|
<nav id="breadcrumb"></nav>
|
|
</div>
|
|
|
|
<article data-uid="CapyKit.Helpers.SecurityHelper">
|
|
|
|
|
|
|
|
<h1 id="CapyKit_Helpers_SecurityHelper" data-uid="CapyKit.Helpers.SecurityHelper" class="text-break">
|
|
Class SecurityHelper
|
|
</h1>
|
|
|
|
<div class="facts text-secondary">
|
|
<dl><dt>Namespace</dt><dd><a class="xref" href="CapyKit.html">CapyKit</a>.<a class="xref" href="CapyKit.Helpers.html">Helpers</a></dd></dl>
|
|
<dl><dt>Assembly</dt><dd>CapyKit.dll</dd></dl>
|
|
</div>
|
|
|
|
<div class="markdown summary"><p>A class that contains methods for managing secure data processing and cryptography.</p>
|
|
</div>
|
|
<div class="markdown conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public class SecurityHelper</code></pre>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<dl class="typelist inheritance">
|
|
<dt>Inheritance</dt>
|
|
<dd>
|
|
<div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
|
|
<div><span class="xref">SecurityHelper</span></div>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
<dl class="typelist inheritedMembers">
|
|
<dt>Inherited Members</dt>
|
|
<dd>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<dl class="typelist extensionMethods">
|
|
<dt>Extension Methods</dt>
|
|
<dd>
|
|
<div>
|
|
<a class="xref" href="CapyKit.Extensions.ObjectExtensions.html#CapyKit_Extensions_ObjectExtensions_UpdateProperties__1___0___0_">ObjectExtensions.UpdateProperties<T>(T, T)</a>
|
|
</div>
|
|
<div>
|
|
<a class="xref" href="CapyKit.Extensions.ObjectExtensions.html#CapyKit_Extensions_ObjectExtensions_UpdateProperties_System_Object_System_Object_">ObjectExtensions.UpdateProperties(object, object)</a>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
|
|
|
|
|
|
|
|
<h2 class="section" id="methods">Methods
|
|
</h2>
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_CompareHashedPassword_" data-uid="CapyKit.Helpers.SecurityHelper.CompareHashedPassword*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_CompareHashedPassword_CapyKit_Password_System_String_System_Byte___CapyKit_IPasswordAlgorithm_System_Object___" data-uid="CapyKit.Helpers.SecurityHelper.CompareHashedPassword(CapyKit.Password,System.String,System.Byte[],CapyKit.IPasswordAlgorithm,System.Object[])">
|
|
CompareHashedPassword(Password, string, byte[], IPasswordAlgorithm, params object[])
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Compares an unencrypted <code class="paramref">password</code> with a stored, encrypted <code class="paramref">existingPassword</code>.
|
|
This method uses the specified <code class="paramref">algorithm</code> to retrieve the hashed version
|
|
of the <code class="paramref">password</code> and then compares it with the <code class="paramref">existingPassword</code>.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static bool CompareHashedPassword(Password existingPassword, string password, byte[] salt, IPasswordAlgorithm algorithm, params object[] args)</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>existingPassword</code> <a class="xref" href="CapyKit.Password.html">Password</a></dt>
|
|
<dd><p>The existing, encrypted password.</p>
|
|
</dd>
|
|
<dt><code>password</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd><p>The unencrypted password to be compared.</p>
|
|
</dd>
|
|
<dt><code>salt</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>[]</dt>
|
|
<dd><p>The salt value used in password hashing.</p>
|
|
</dd>
|
|
<dt><code>algorithm</code> <a class="xref" href="CapyKit.IPasswordAlgorithm.html">IPasswordAlgorithm</a></dt>
|
|
<dd><p>The password hashing algorithm.</p>
|
|
</dd>
|
|
<dt><code>args</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a>[]</dt>
|
|
<dd><p>Additional arguments required for constructing the password algorithm instance.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></dt>
|
|
<dd><p><a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">true</a> if hash comparison succeeds, <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">false</a> if it fails.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_CompareHashedPassword_" data-uid="CapyKit.Helpers.SecurityHelper.CompareHashedPassword*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_CompareHashedPassword__1_CapyKit_Password_System_String_System_Byte___System_Object___" data-uid="CapyKit.Helpers.SecurityHelper.CompareHashedPassword``1(CapyKit.Password,System.String,System.Byte[],System.Object[])">
|
|
CompareHashedPassword<T>(Password, string, byte[], params object[])
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Compares an unencrypted <code class="paramref">password</code> with a stored, encrypted <code class="paramref">existingPassword</code>.
|
|
This method uses the specified password algorithm type <code class="typeparamref">T</code> to retrieve the hashed version
|
|
of the <code class="paramref">password</code> and then compares it with the <code class="paramref">existingPassword</code>.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static bool CompareHashedPassword<T>(Password existingPassword, string password, byte[] salt, params object[] args)</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>existingPassword</code> <a class="xref" href="CapyKit.Password.html">Password</a></dt>
|
|
<dd><p>The existing, encrypted password.</p>
|
|
</dd>
|
|
<dt><code>password</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd><p>The unencrypted password to be compared.</p>
|
|
</dd>
|
|
<dt><code>salt</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>[]</dt>
|
|
<dd><p>The salt value used in password hashing.</p>
|
|
</dd>
|
|
<dt><code>args</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a>[]</dt>
|
|
<dd><p>Additional arguments required for constructing the password algorithm instance.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></dt>
|
|
<dd><p><a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">true</a> if hash comparison succeeds, <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">false</a> if it fails.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Type Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>T</code></dt>
|
|
<dd><p>The type of the password hashing algorithm.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_CompareSessionID_" data-uid="CapyKit.Helpers.SecurityHelper.CompareSessionID*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_CompareSessionID_System_String_System_String_" data-uid="CapyKit.Helpers.SecurityHelper.CompareSessionID(System.String,System.String)">
|
|
CompareSessionID(string, string)
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Compares two session identifiers.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static bool CompareSessionID(string first, string second)</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>first</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd><p>The first session identifier.</p>
|
|
</dd>
|
|
<dt><code>second</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd><p>The second session identifier.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></dt>
|
|
<dd><p><a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">true</a> if comparison succeeds, <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">false</a> if not.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_GetPassword_" data-uid="CapyKit.Helpers.SecurityHelper.GetPassword*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_GetPassword__1_System_String_System_Byte___System_Object___" data-uid="CapyKit.Helpers.SecurityHelper.GetPassword``1(System.String,System.Byte[],System.Object[])">
|
|
GetPassword<T>(string, byte[], params object[])
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Retrieves a <a class="xref" href="CapyKit.Password.html">Password</a> object using the specified password, salt, and optional
|
|
constructor arguments.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static Password GetPassword<T>(string password, byte[] salt, params object[] args) where T : IPasswordAlgorithm</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>password</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd><p>The plaintext password to be hashed.</p>
|
|
</dd>
|
|
<dt><code>salt</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>[]</dt>
|
|
<dd><p>A random value used as an additional input to the one-way function that hashes data, a
|
|
password or passphrase. This is used to make each output different for the same input
|
|
thus adding security.</p>
|
|
</dd>
|
|
<dt><code>args</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a>[]</dt>
|
|
<dd><p>Optional constructor arguments for the <a class="xref" href="CapyKit.IPasswordAlgorithm.html">IPasswordAlgorithm</a> implementation
|
|
instance.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="CapyKit.Password.html">Password</a></dt>
|
|
<dd><p>A new <a class="xref" href="CapyKit.Password.html">Password</a> object with the given password and salt, as well as an instance
|
|
of <code class="typeparamref">T</code> created using the provided constructor arguments.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Type Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>T</code></dt>
|
|
<dd><p>The type of <a class="xref" href="CapyKit.IPasswordAlgorithm.html">IPasswordAlgorithm</a> implementation to use.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h4 class="section" id="CapyKit_Helpers_SecurityHelper_GetPassword__1_System_String_System_Byte___System_Object____remarks">Remarks</h4>
|
|
<div class="markdown level1 remarks"><p>This method uses reflection to find a constructor for the specified password algorithm type (<code class="typeparamref">T</code>).
|
|
It emits an error event if a suitable constructor is not found or if there is an error invoking the constructor.</p>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_GetPassword_" data-uid="CapyKit.Helpers.SecurityHelper.GetPassword*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_GetPassword__1_System_String_System_Object___" data-uid="CapyKit.Helpers.SecurityHelper.GetPassword``1(System.String,System.Object[])">
|
|
GetPassword<T>(string, params object[])
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Retrieves a <a class="xref" href="CapyKit.Password.html">Password</a> object using the specified password and generates a random salt value.
|
|
Then it uses that salt to call the overloaded <a class="xref" href="CapyKit.Helpers.SecurityHelper.html#CapyKit_Helpers_SecurityHelper_GetPassword__1_System_String_System_Byte___System_Object___">GetPassword<T>(string, byte[], params object[])</a> method with the given password and
|
|
the generated salt as arguments.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static Password GetPassword<T>(string password, params object[] args)</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>password</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd><p>The plaintext password to be hashed.</p>
|
|
</dd>
|
|
<dt><code>args</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a>[]</dt>
|
|
<dd><p>Optional constructor arguments for the <a class="xref" href="CapyKit.IPasswordAlgorithm.html">IPasswordAlgorithm</a> implementation
|
|
instance.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="CapyKit.Password.html">Password</a></dt>
|
|
<dd><p>A new <a class="xref" href="CapyKit.Password.html">Password</a> object with the given password and a randomly generated salt, as well as an
|
|
instance of <code class="typeparamref">T</code> created using any optional constructor arguments provided.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Type Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>T</code></dt>
|
|
<dd><p>The type of <a class="xref" href="CapyKit.IPasswordAlgorithm.html">IPasswordAlgorithm</a> implementation to use.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dl class="typelist seealso">
|
|
<dt>See Also</dt>
|
|
<dd>
|
|
<div><span class="xref">SALT_SIZE</span></div>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_GetRandomPassword_" data-uid="CapyKit.Helpers.SecurityHelper.GetRandomPassword*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_GetRandomPassword_System_Int32_CapyKit_Helpers_ValidCharacterCollection___" data-uid="CapyKit.Helpers.SecurityHelper.GetRandomPassword(System.Int32,CapyKit.Helpers.ValidCharacterCollection[])">
|
|
GetRandomPassword(int, params ValidCharacterCollection[])
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Gets a cryptographically strong random password.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static string GetRandomPassword(int length, params ValidCharacterCollection[] validCharacters)</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>length</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
|
|
<dd><p>The length of the password to generate.</p>
|
|
</dd>
|
|
<dt><code>validCharacters</code> <a class="xref" href="CapyKit.Helpers.ValidCharacterCollection.html">ValidCharacterCollection</a>[]</dt>
|
|
<dd><p>An array of <a class="xref" href="CapyKit.Helpers.ValidCharacterCollection.html">ValidCharacterCollection</a> enumeration values representing the desired
|
|
character sets.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd><p>The password.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_GetRandomString_" data-uid="CapyKit.Helpers.SecurityHelper.GetRandomString*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_GetRandomString_System_Int32_" data-uid="CapyKit.Helpers.SecurityHelper.GetRandomString(System.Int32)">
|
|
GetRandomString(int)
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>A convenience method to generate a random string of the specified length using all character sets.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static string GetRandomString(int length)</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>length</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
|
|
<dd><p>The desired length of the generated random string.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd></dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dl class="typelist seealso">
|
|
<dt>See Also</dt>
|
|
<dd>
|
|
<div><a class="xref" href="CapyKit.Helpers.ValidCharacterCollection.html">ValidCharacterCollection</a></div>
|
|
<div><a class="xref" href="CapyKit.Helpers.SecurityHelper.html#CapyKit_Helpers_SecurityHelper_GetRandomString_System_Int32_CapyKit_Helpers_ValidCharacterCollection___">GetRandomString(int, params ValidCharacterCollection[])</a></div>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_GetRandomString_" data-uid="CapyKit.Helpers.SecurityHelper.GetRandomString*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_GetRandomString_System_Int32_CapyKit_Helpers_ValidCharacterCollection___" data-uid="CapyKit.Helpers.SecurityHelper.GetRandomString(System.Int32,CapyKit.Helpers.ValidCharacterCollection[])">
|
|
GetRandomString(int, params ValidCharacterCollection[])
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Gets a cryptographically strong random string using the character values found in VALID_CHARACTERS.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static string GetRandomString(int length, params ValidCharacterCollection[] validChars)</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>length</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
|
|
<dd><p>The length of the string to create.</p>
|
|
</dd>
|
|
<dt><code>validChars</code> <a class="xref" href="CapyKit.Helpers.ValidCharacterCollection.html">ValidCharacterCollection</a>[]</dt>
|
|
<dd></dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd><p>The random string.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_GetSalt_" data-uid="CapyKit.Helpers.SecurityHelper.GetSalt*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_GetSalt_System_Int32_" data-uid="CapyKit.Helpers.SecurityHelper.GetSalt(System.Int32)">
|
|
GetSalt(int)
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Generates a random byte array that can act as a salt.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static byte[] GetSalt(int length = 32)</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>length</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></dt>
|
|
<dd><p>(Optional) The desired length of the generated byte array.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>[]</dt>
|
|
<dd><p>An array of byte.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h4 class="section" id="CapyKit_Helpers_SecurityHelper_GetSalt_System_Int32__remarks">Remarks</h4>
|
|
<div class="markdown level1 remarks"><p>A default length of <span class="xref">CapyKit.Helpers.SecurityHelper.SALT_SIZE</span> is provided as a sane default. Larger values can be used for increased
|
|
entropy.</p>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_Pbkdf2_" data-uid="CapyKit.Helpers.SecurityHelper.Pbkdf2*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_Pbkdf2_System_String_" data-uid="CapyKit.Helpers.SecurityHelper.Pbkdf2(System.String)">
|
|
Pbkdf2(string)
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Generates a new <a class="xref" href="CapyKit.Password.html">Password</a> object using the PBKDF2 algorithm with the provided <code class="paramref">password</code>.
|
|
This overload of the method generates a random salt value for added security.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static Password Pbkdf2(string password)</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>password</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd><p>The clear text password to be hashed.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="CapyKit.Password.html">Password</a></dt>
|
|
<dd><p>A new <a class="xref" href="CapyKit.Password.html">Password</a> object containing the hashed password and a randomly generated salt.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h4 class="section" id="CapyKit_Helpers_SecurityHelper_Pbkdf2_System_String__remarks">Remarks</h4>
|
|
<div class="markdown level1 remarks"><p>This method uses the PBKDF2 (Password-Based Key Derivation Function 2) algorithm to generate
|
|
a new password hash. The algorithm iteratively applies a pseudorandom function to the
|
|
password and salt, which increases the security of the resulting hash. In this overload,
|
|
a random salt value is generated using <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">GetRandomBytes(int)</a> method.</p>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<a id="CapyKit_Helpers_SecurityHelper_Pbkdf2_" data-uid="CapyKit.Helpers.SecurityHelper.Pbkdf2*"></a>
|
|
|
|
<h3 id="CapyKit_Helpers_SecurityHelper_Pbkdf2_System_String_System_Byte___" data-uid="CapyKit.Helpers.SecurityHelper.Pbkdf2(System.String,System.Byte[])">
|
|
Pbkdf2(string, byte[])
|
|
|
|
</h3>
|
|
|
|
<div class="markdown level1 summary"><p>Generates a new <a class="xref" href="CapyKit.Password.html">Password</a> object using the PBKDF2 algorithm with the provided <code class="paramref">password</code>
|
|
and <code class="paramref">salt</code>.</p>
|
|
</div>
|
|
<div class="markdown level1 conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static Password Pbkdf2(string password, byte[] salt)</code></pre>
|
|
</div>
|
|
|
|
<h4 class="section">Parameters</h4>
|
|
<dl class="parameters">
|
|
<dt><code>password</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></dt>
|
|
<dd><p>The clear text password to be hashed.</p>
|
|
</dd>
|
|
<dt><code>salt</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>[]</dt>
|
|
<dd><p>A random value used to add an additional layer of security to the generated hash.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<h4 class="section">Returns</h4>
|
|
<dl class="parameters">
|
|
<dt><a class="xref" href="CapyKit.Password.html">Password</a></dt>
|
|
<dd><p>A new <a class="xref" href="CapyKit.Password.html">Password</a> object containing the hashed password and salt.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h4 class="section" id="CapyKit_Helpers_SecurityHelper_Pbkdf2_System_String_System_Byte____remarks">Remarks</h4>
|
|
<div class="markdown level1 remarks"><p>This method uses the PBKDF2 (Password-Based Key Derivation Function 2) algorithm to generate
|
|
a new password hash. The algorithm iteratively applies a pseudorandom function to the
|
|
password and salt, which increases the security of the resulting hash.</p>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</article>
|
|
|
|
<div class="contribution d-print-none">
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<div class="affix">
|
|
<nav id="affix"></nav>
|
|
</div>
|
|
</main>
|
|
|
|
<div class="container-xxl search-results" id="search-results"></div>
|
|
|
|
<footer class="border-top text-secondary">
|
|
<div class="container-xxl">
|
|
<div class="flex-fill">
|
|
<span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|