1ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrompackage org.bouncycastle.asn1.pkcs; 2ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 3ea26f188e84c7677b943d83cec49372793e81445Brian Carlstromimport java.math.BigInteger; 4ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 5ea26f188e84c7677b943d83cec49372793e81445Brian Carlstromimport org.bouncycastle.asn1.ASN1EncodableVector; 64c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Integer; 74c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Object; 8ea26f188e84c7677b943d83cec49372793e81445Brian Carlstromimport org.bouncycastle.asn1.ASN1OctetString; 94c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Primitive; 10ea26f188e84c7677b943d83cec49372793e81445Brian Carlstromimport org.bouncycastle.asn1.ASN1Sequence; 11ea26f188e84c7677b943d83cec49372793e81445Brian Carlstromimport org.bouncycastle.asn1.DEROctetString; 12ea26f188e84c7677b943d83cec49372793e81445Brian Carlstromimport org.bouncycastle.asn1.DERSequence; 13ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 14ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrompublic class PBEParameter 154c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom extends ASN1Object 16ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom{ 174c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom ASN1Integer iterations; 18ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom ASN1OctetString salt; 19ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 20ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom public PBEParameter( 21ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom byte[] salt, 22ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom int iterations) 23ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom { 24ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom if (salt.length != 8) 25ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom { 26ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom throw new IllegalArgumentException("salt length must be 8"); 27ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom } 28ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom this.salt = new DEROctetString(salt); 294c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom this.iterations = new ASN1Integer(iterations); 30ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom } 31ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 324c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom private PBEParameter( 33ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom ASN1Sequence seq) 34ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom { 35ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom salt = (ASN1OctetString)seq.getObjectAt(0); 364c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom iterations = (ASN1Integer)seq.getObjectAt(1); 37ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom } 38ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 39ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom public static PBEParameter getInstance( 40ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom Object obj) 41ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom { 42ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom if (obj instanceof PBEParameter) 43ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom { 44ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom return (PBEParameter)obj; 45ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom } 464c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom else if (obj != null) 47ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom { 484c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom return new PBEParameter(ASN1Sequence.getInstance(obj)); 49ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom } 50ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 514c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom return null; 52ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom } 53ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 54ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom public BigInteger getIterationCount() 55ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom { 56ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom return iterations.getValue(); 57ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom } 58ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 59ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom public byte[] getSalt() 60ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom { 61ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom return salt.getOctets(); 62ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom } 63ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 644c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom public ASN1Primitive toASN1Primitive() 65ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom { 66ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom ASN1EncodableVector v = new ASN1EncodableVector(); 67ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 68ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom v.add(salt); 69ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom v.add(iterations); 70ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom 71ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom return new DERSequence(v); 72ea26f188e84c7677b943d83cec49372793e81445Brian Carlstrom } 734c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom} 74