1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.asn1.pkcs; 2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 3b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport java.math.BigInteger; 4b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 5b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1EncodableVector; 64c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Integer; 74c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Object; 8b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1OctetString; 94c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Primitive; 10b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1Sequence; 11b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.DEROctetString; 12b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.DERSequence; 13b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 14b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic class PKCS12PBEParams 154c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom extends ASN1Object 16b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{ 174c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom ASN1Integer iterations; 18b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1OctetString iv; 19b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 20b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public PKCS12PBEParams( 21b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam byte[] salt, 22b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam int iterations) 23b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 24b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.iv = new DEROctetString(salt); 254c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom this.iterations = new ASN1Integer(iterations); 26b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 27b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 284c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom private PKCS12PBEParams( 29b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1Sequence seq) 30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 31b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam iv = (ASN1OctetString)seq.getObjectAt(0); 324c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom iterations = ASN1Integer.getInstance(seq.getObjectAt(1)); 33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 34b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static PKCS12PBEParams getInstance( 36b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Object obj) 37b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 38b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (obj instanceof PKCS12PBEParams) 39b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 40b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return (PKCS12PBEParams)obj; 41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 424c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom else if (obj != null) 43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 444c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom return new PKCS12PBEParams(ASN1Sequence.getInstance(obj)); 45b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 46b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 474c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom return null; 48b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 49b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 50b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public BigInteger getIterations() 51b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 52b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return iterations.getValue(); 53b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 54b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 55b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public byte[] getIV() 56b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 57b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return iv.getOctets(); 58b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 59b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 604c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom public ASN1Primitive toASN1Primitive() 61b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 62b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1EncodableVector v = new ASN1EncodableVector(); 63b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 64b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam v.add(iv); 65b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam v.add(iterations); 66b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 67b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return new DERSequence(v); 68b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 69b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam} 70