Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PbePkcs12.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4
6{
10 public abstract class PbePkcs12 : PasswordEncryption
11 {
12 private readonly byte[] salt;
13 private readonly byte[] key;
14 private readonly int iterations;
15
23 public PbePkcs12(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 this.key = PfxEncoder.PRF(HashFunction, Iterations,
36 PfxEncoder.FormatPassword(Password), this.salt, KeyLength, 1);
37 }
38
42 protected byte[] Key => this.key;
43
47 protected int Iterations => this.iterations;
48
52 protected byte[] Salt => this.salt;
53
59 {
60 Der.StartSEQUENCE();
62 Der.StartSEQUENCE(); // pkcs-12PbeParams
63 Der.OCTET_STRING(this.salt);
64 Der.INTEGER(this.iterations);
65 Der.EndSEQUENCE(); // End of pkcs-12PbeParams
66 Der.EndSEQUENCE();
67 }
68
69 }
70}
Encodes data using the Distinguished Encoding Rules (DER), as defined in X.690
Definition: DerEncoder.cs:40
void EndSEQUENCE()
Ends the current SEQUENCE.
Definition: DerEncoder.cs:483
void OBJECT_IDENTIFIER(string OID)
Encodes an OBJECT IDENTIFIER value.
Definition: DerEncoder.cs:343
void INTEGER(long Value)
Encodes an INTEGER value.
Definition: DerEncoder.cs:99
void StartSEQUENCE()
Starts a SEQUENCE.
Definition: DerEncoder.cs:465
void OCTET_STRING(byte[] Value)
Encodes an OCTET STRING value.
Definition: DerEncoder.cs:308
Abstract base class for password-based encryption algorithms
abstract string AlgorithmOID
Object Identity for the algorithm.
Implements a password-based encryption algorithm, as defined in §C, RFC 7292 (PKCS#12).
Definition: PbePkcs12.cs:11
int Iterations
Number of iterations.
Definition: PbePkcs12.cs:47
override void EncodePkcs5AlgorithmIdentifier(DerEncoder Der)
Encodes the AlgorithmIdentifier, as defined in PKCS#5 (RFC 2898).
Definition: PbePkcs12.cs:58
PbePkcs12(string Password, int Iterations, int KeyLength, HashFunction HashFunction)
Implements a password-based encryption algorithm, as defined in §C, RFC 7292 (PKCS#12).
Definition: PbePkcs12.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
HashFunction
Hash method enumeration.
Definition: Hashes.cs:28