66import org .bouncycastle .asn1 .ASN1BitString ;
77import org .bouncycastle .asn1 .ASN1Encodable ;
88import org .bouncycastle .asn1 .ASN1EncodableVector ;
9+ import org .bouncycastle .asn1 .ASN1Encoding ;
910import org .bouncycastle .asn1 .ASN1Integer ;
1011import org .bouncycastle .asn1 .ASN1Object ;
1112import org .bouncycastle .asn1 .ASN1OctetString ;
@@ -95,6 +96,27 @@ private static int getVersionValue(ASN1Integer version)
9596 return versionValue ;
9697 }
9798
99+ /**
100+ * Construct a PrivateKeyInfo around a raw encoding.
101+ *
102+ * @param privateKeyAlgorithm algorithm identifier for the private key.
103+ * @param privateKey byte encoding of the private key, used as a raw encoding.
104+ */
105+ public PrivateKeyInfo (
106+ AlgorithmIdentifier privateKeyAlgorithm ,
107+ byte [] privateKey )
108+ throws IOException
109+ {
110+ this (privateKeyAlgorithm , privateKey , null , null );
111+ }
112+
113+ /**
114+ * Construct a PrivateKeyInfo around an ASN.1 structure/primitive.
115+ *
116+ * @param privateKeyAlgorithm algorithm identifier for the private key.
117+ * @param privateKey the ASN.1 structure/primitive representing the private key.
118+ * @throws IOException if encoding the privateKey object into an OCTET STRING fails.
119+ */
98120 public PrivateKeyInfo (
99121 AlgorithmIdentifier privateKeyAlgorithm ,
100122 ASN1Encodable privateKey )
@@ -103,6 +125,14 @@ public PrivateKeyInfo(
103125 this (privateKeyAlgorithm , privateKey , null , null );
104126 }
105127
128+ /**
129+ * Construct a PrivateKeyInfo around an ASN.1 structure/primitive with attributes.
130+ *
131+ * @param privateKeyAlgorithm algorithm identifier for the private key.
132+ * @param privateKey the ASN.1 structure/primitive representing the private key.
133+ * @param attributes attributes associated with private key.
134+ * @throws IOException if encoding the privateKey object into an OCTET STRING fails.
135+ */
106136 public PrivateKeyInfo (
107137 AlgorithmIdentifier privateKeyAlgorithm ,
108138 ASN1Encodable privateKey ,
@@ -112,12 +142,55 @@ public PrivateKeyInfo(
112142 this (privateKeyAlgorithm , privateKey , attributes , null );
113143 }
114144
145+ /**
146+ * Construct a PrivateKeyInfo around an ASN.1 structure/primitive with attributes.
147+ *
148+ * @param privateKeyAlgorithm algorithm identifier for the private key.
149+ * @param privateKey byte encoding of the private key, used as a raw encoding.
150+ * @param attributes attributes associated with private key.
151+ * @throws IOException if encoding the privateKey object into an OCTET STRING fails.
152+ */
153+ public PrivateKeyInfo (
154+ AlgorithmIdentifier privateKeyAlgorithm ,
155+ byte [] privateKey ,
156+ ASN1Set attributes )
157+ throws IOException
158+ {
159+ this (privateKeyAlgorithm , privateKey , attributes , null );
160+ }
161+
162+ /**
163+ * Construct a PrivateKeyInfo around an ASN.1 structure/primitive with attributes and the public key.
164+ *
165+ * @param privateKeyAlgorithm algorithm identifier for the private key.
166+ * @param privateKey the ASN.1 structure/primitive representing the private key.
167+ * @param attributes attributes associated with private key.
168+ * @param publicKey public key encoding.
169+ * @throws IOException if encoding the privateKey object into an OCTET STRING fails.
170+ */
115171 public PrivateKeyInfo (
116172 AlgorithmIdentifier privateKeyAlgorithm ,
117173 ASN1Encodable privateKey ,
118174 ASN1Set attributes ,
119175 byte [] publicKey )
120176 throws IOException
177+ {
178+ this (privateKeyAlgorithm , privateKey .toASN1Primitive ().getEncoded (ASN1Encoding .DER ), attributes , publicKey );
179+ }
180+
181+ /**
182+ * Construct a PrivateKeyInfo around a raw encoding with attributes and the public key.
183+ *
184+ * @param privateKeyAlgorithm algorithm identifier for the private key.
185+ * @param privateKey byte encoding of the private key, used as a raw encoding.
186+ * @param attributes attributes associated with private key.
187+ * @param publicKey public key encoding.
188+ */
189+ public PrivateKeyInfo (
190+ AlgorithmIdentifier privateKeyAlgorithm ,
191+ byte [] privateKey ,
192+ ASN1Set attributes ,
193+ byte [] publicKey )
121194 {
122195 this .version = new ASN1Integer (publicKey != null ? BigIntegers .ONE : BigIntegers .ZERO );
123196 this .privateKeyAlgorithm = privateKeyAlgorithm ;
@@ -222,7 +295,7 @@ public boolean hasPublicKey()
222295 *
223296 * @return the public key as an ASN.1 primitive.
224297 * @throws IOException - if the bit string doesn't represent a DER
225- * encoded object.
298+ * encoded object.
226299 */
227300 public ASN1Encodable parsePublicKey ()
228301 throws IOException
0 commit comments