01: package org.bouncycastle.asn1.pkcs;
02:
03: import java.math.BigInteger;
04:
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.ASN1EncodableVector;
07: import org.bouncycastle.asn1.ASN1OctetString;
08: import org.bouncycastle.asn1.ASN1Sequence;
09: import org.bouncycastle.asn1.DERInteger;
10: import org.bouncycastle.asn1.DERObject;
11: import org.bouncycastle.asn1.DEROctetString;
12: import org.bouncycastle.asn1.DERSequence;
13:
14: public class PKCS12PBEParams extends ASN1Encodable {
15: DERInteger iterations;
16: ASN1OctetString iv;
17:
18: public PKCS12PBEParams(byte[] salt, int iterations) {
19: this .iv = new DEROctetString(salt);
20: this .iterations = new DERInteger(iterations);
21: }
22:
23: public PKCS12PBEParams(ASN1Sequence seq) {
24: iv = (ASN1OctetString) seq.getObjectAt(0);
25: iterations = (DERInteger) seq.getObjectAt(1);
26: }
27:
28: public static PKCS12PBEParams getInstance(Object obj) {
29: if (obj instanceof PKCS12PBEParams) {
30: return (PKCS12PBEParams) obj;
31: } else if (obj instanceof ASN1Sequence) {
32: return new PKCS12PBEParams((ASN1Sequence) obj);
33: }
34:
35: throw new IllegalArgumentException("unknown object in factory");
36: }
37:
38: public BigInteger getIterations() {
39: return iterations.getValue();
40: }
41:
42: public byte[] getIV() {
43: return iv.getOctets();
44: }
45:
46: public DERObject toASN1Object() {
47: ASN1EncodableVector v = new ASN1EncodableVector();
48:
49: v.add(iv);
50: v.add(iterations);
51:
52: return new DERSequence(v);
53: }
54: }
|