summary refs log tree commit diff
path: root/crypto/src/asn1/pkcs/PKCS12PBEParams.cs
blob: 7521f93eac8114bf9f909b87c33491ebf5e1cb49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Math;

namespace Org.BouncyCastle.Asn1.Pkcs
{
    public class Pkcs12PbeParams
        : Asn1Encodable
    {
        private readonly DerInteger iterations;
        private readonly Asn1OctetString iv;

		public Pkcs12PbeParams(
            byte[]	salt,
            int		iterations)
        {
            this.iv = new DerOctetString(salt);
            this.iterations = new DerInteger(iterations);
        }

		private Pkcs12PbeParams(
            Asn1Sequence seq)
        {
			if (seq.Count != 2)
				throw new ArgumentException("Wrong number of elements in sequence", "seq");

			iv = Asn1OctetString.GetInstance(seq[0]);
            iterations = DerInteger.GetInstance(seq[1]);
        }

		public static Pkcs12PbeParams GetInstance(
            object obj)
        {
            if (obj is Pkcs12PbeParams)
            {
                return (Pkcs12PbeParams) obj;
            }

			if (obj is Asn1Sequence)
            {
                return new Pkcs12PbeParams((Asn1Sequence) obj);
            }

			throw new ArgumentException("Unknown object in factory: " + obj.GetType().FullName, "obj");
		}

		public BigInteger Iterations
		{
			get { return iterations.Value; }
		}

		public byte[] GetIV()
        {
            return iv.GetOctets();
        }

		public override Asn1Object ToAsn1Object()
        {
			return new DerSequence(iv, iterations);
        }
    }
}