Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Pbkdf1.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4
6{
10 public abstract class Pbkdf1 : PasswordEncryption
11 {
12 private readonly byte[] salt;
13 private readonly byte[] key;
14 private readonly int iterations;
15
23 public Pbkdf1(string Password, int Iterations, int KeyLength, HashFunction HashFunction)
24 : base(Password)
25 {
26 if (Iterations <= 0)
27 throw new ArgumentException("Must be postitive.", nameof(Iterations));
28
29 if (KeyLength <= 0)
30 throw new ArgumentException("Must be postitive.", nameof(Iterations));
31
32 this.iterations = Iterations;
33 this.salt = PfxEncoder.GetRandomBytes(8);
34
35 byte[] Bin = Hashes.ComputeHash(HashFunction,
36 Primitives.CONCAT(Encoding.UTF8.GetBytes(Password), this.salt));
37
38 while (--Iterations >= 0)
40
41 if (KeyLength > Bin.Length)
42 throw new ArgumentException("Derived key too long.", nameof(KeyLength));
43
44 this.key = new byte[KeyLength];
45
46 Array.Copy(Bin, 0, this.key, 0, KeyLength);
47 }
48 }
49}
Contains methods for simple hash calculations.
Definition: Hashes.cs:59
static byte[] ComputeHash(HashFunction Function, byte[] Data)
Computes a hash of a block of binary data.
Definition: Hashes.cs:214
Abstract base class for password-based encryption algorithms
Implements the PBKDF1 key derivation function, as defined in §5.1, RFC 2898 (PKCS#5).
Definition: Pbkdf1.cs:11
Pbkdf1(string Password, int Iterations, int KeyLength, HashFunction HashFunction)
Implements the PBKDF1 key derivation function, as defined in §5.1, RFC 2898 (PKCS#5).
Definition: Pbkdf1.cs:23
Encodes certificates and keys into PKCS#12 or PFX files.
Definition: PfxEncoder.cs:14
static byte[] GetRandomBytes(int NrBytes)
Gets a number of random bytes.
Definition: PfxEncoder.cs:33
Contains static functions used by different algorithms.
Definition: Primitives.cs:11
static byte[] CONCAT(params byte[][] OctetStrings)
Concatenates a series of octet strings.
Definition: Primitives.cs:17
HashFunction
Hash method enumeration.
Definition: Hashes.cs:28