01: package org.bouncycastle.asn1.pkcs;
02:
03: import java.util.Enumeration;
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.DERObject;
10: import org.bouncycastle.asn1.DEROctetString;
11: import org.bouncycastle.asn1.DERSequence;
12: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
13:
14: public class EncryptedPrivateKeyInfo extends ASN1Encodable {
15: private AlgorithmIdentifier algId;
16: private ASN1OctetString data;
17:
18: public EncryptedPrivateKeyInfo(ASN1Sequence seq) {
19: Enumeration e = seq.getObjects();
20:
21: algId = AlgorithmIdentifier.getInstance(e.nextElement());
22: data = (ASN1OctetString) e.nextElement();
23: }
24:
25: public EncryptedPrivateKeyInfo(AlgorithmIdentifier algId,
26: byte[] encoding) {
27: this .algId = algId;
28: this .data = new DEROctetString(encoding);
29: }
30:
31: public static EncryptedPrivateKeyInfo getInstance(Object obj) {
32: if (obj instanceof EncryptedData) {
33: return (EncryptedPrivateKeyInfo) obj;
34: } else if (obj instanceof ASN1Sequence) {
35: return new EncryptedPrivateKeyInfo((ASN1Sequence) obj);
36: }
37:
38: throw new IllegalArgumentException("unknown object in factory");
39: }
40:
41: public AlgorithmIdentifier getEncryptionAlgorithm() {
42: return algId;
43: }
44:
45: public byte[] getEncryptedData() {
46: return data.getOctets();
47: }
48:
49: /**
50: * Produce an object suitable for an ASN1OutputStream.
51: * <pre>
52: * EncryptedPrivateKeyInfo ::= SEQUENCE {
53: * encryptionAlgorithm AlgorithmIdentifier {{KeyEncryptionAlgorithms}},
54: * encryptedData EncryptedData
55: * }
56: *
57: * EncryptedData ::= OCTET STRING
58: *
59: * KeyEncryptionAlgorithms ALGORITHM-IDENTIFIER ::= {
60: * ... -- For local profiles
61: * }
62: * </pre>
63: */
64: public DERObject toASN1Object() {
65: ASN1EncodableVector v = new ASN1EncodableVector();
66:
67: v.add(algId);
68: v.add(data);
69:
70: return new DERSequence(v);
71: }
72: }
|