summaryrefslogtreecommitdiff
path: root/manual/html_node/PKCS-12-API.html
blob: f526593cfa5dcc9ac40937a9346470e52785b46d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This manual is last updated 29 July 2014 for version
3.3.8 of GnuTLS.

Copyright (C) 2001-2013 Free Software Foundation, Inc.\\
Copyright (C) 2001-2013 Nikos Mavrogiannopoulos

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.  A
copy of the license is included in the section entitled "GNU Free
Documentation License". -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GnuTLS 3.3.8: PKCS 12 API</title>

<meta name="description" content="GnuTLS 3.3.8: PKCS 12 API">
<meta name="keywords" content="GnuTLS 3.3.8: PKCS 12 API">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Function-and-Data-Index.html#Function-and-Data-Index" rel="index" title="Function and Data Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="API-reference.html#API-reference" rel="up" title="API reference">
<link href="PKCS-11-API.html#PKCS-11-API" rel="next" title="PKCS 11 API">
<link href="OpenPGP-API.html#OpenPGP-API" rel="prev" title="OpenPGP API">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
body { 
	margin: 2%;
	padding: 0 5%;
	background: #ffffff;
}
h1,h2,h3,h4,h5 {
    font-weight: bold;
    padding: 5px 5px 5px 5px;
    background-color: #c2e0ff;
    color: #336699;
}
h1 {
    padding: 2em 2em 2em 5%;
    color: white;
    background: #336699;
    text-align: center;
    letter-spacing: 3px;
}
h2 { text-decoration: underline; }
pre {
  margin: 0 5%;
  padding: 0.5em;
}
pre.example,pre.verbatim {
  padding-bottom: 1em;

  border: solid #c2e0ff;
  background: #f0faff;
  border-width: 1px 1px 1px 5px;
  margin: 1em auto;
  width: 90%;
}

div.node {
  margin: 0 -5% 0 -2%;
  padding: 0.5em 0.5em;
  margin-top: 0.5em;
  margin-bottom: 0.5em;
  font-weight: bold;
}
dd, li {
  padding-top: 0.1em;
  padding-bottom: 0.1em;
}
div.float {

  margin-bottom: 0.5em;
  text-align: center;
}

table {
  text-align: left;
  margin-left:auto;
  margin-right:auto;
  width: 50%;
}

th {
  padding: 0;
  color: #336699;
  background-color: #c2e0ff;
  border: solid #000000;
  border-width: 0px;
  margin: 1em auto;
  text-align: center;
  margin-left:auto;
  margin-right:auto;
}

td {
  padding: 0;
  border: solid #000000;
  background-color: #f0faff;
  border-width: 0px;
  margin: 1em auto;
  text-align: left;
  margin-left:auto;
  margin-right:auto;
  padding-left: 1em;
}

dl {
  text-align: left;
  margin-left:auto;
  margin-right:auto;
  width: 50%;

  padding-left: 1em;
  border: solid #c2e0ff;
  background: #f0faff;
  border-width: 5px 1px 1px 1px;
  margin: 1em auto;
}

-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="PKCS-12-API"></a>
<div class="header">
<p>
Next: <a href="PKCS-11-API.html#PKCS-11-API" accesskey="n" rel="next">PKCS 11 API</a>, Previous: <a href="OpenPGP-API.html#OpenPGP-API" accesskey="p" rel="prev">OpenPGP API</a>, Up: <a href="API-reference.html#API-reference" accesskey="u" rel="up">API reference</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Function-and-Data-Index.html#Function-and-Data-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="PKCS-12-API-1"></a>
<h3 class="section">E.6 PKCS 12 API</h3>

<p>The following functions are to be used for PKCS 12 handling.
Their prototypes lie in <samp>gnutls/pkcs12.h</samp>.
</p>

<a name="gnutls_005fpkcs12_005fbag_005fdecrypt-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_decrypt</h4>
<a name="gnutls_005fpkcs12_005fbag_005fdecrypt"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fdecrypt"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_decrypt</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, const char * <var>pass</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>pass</var>: The password used for encryption, must be ASCII.
</p>
<p>This function will decrypt the given encrypted bag and return 0 on
success.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned,
otherwise a negative error code is returned.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fdeinit-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_deinit</h4>
<a name="gnutls_005fpkcs12_005fbag_005fdeinit"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fdeinit"></a>Function: <em>void</em> <strong>gnutls_pkcs12_bag_deinit</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>)</em></dt>
<dd><p><var>bag</var>: The structure to be initialized
</p>
<p>This function will deinitialize a PKCS12 Bag structure.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fencrypt-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_encrypt</h4>
<a name="gnutls_005fpkcs12_005fbag_005fencrypt"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fencrypt"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_encrypt</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, const char * <var>pass</var>, unsigned int <var>flags</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>pass</var>: The password used for encryption, must be ASCII
</p>
<p><var>flags</var>: should be one of <code>gnutls_pkcs_encrypt_flags_t</code>  elements bitwise or&rsquo;d
</p>
<p>This function will encrypt the given bag.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned,
otherwise a negative error code is returned.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fget_005fcount-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_get_count</h4>
<a name="gnutls_005fpkcs12_005fbag_005fget_005fcount"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fget_005fcount"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_get_count</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p>This function will return the number of the elements withing the bag.
</p>
<p><strong>Returns:</strong> Number of elements in bag, or an negative error code on
error.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fget_005fdata-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_get_data</h4>
<a name="gnutls_005fpkcs12_005fbag_005fget_005fdata"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fget_005fdata"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_get_data</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, int <var>indx</var>, gnutls_datum_t * <var>data</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>indx</var>: The element of the bag to get the data from
</p>
<p><var>data</var>: where the bag&rsquo;s data will be. Should be treated as constant.
</p>
<p>This function will return the bag&rsquo;s data. The data is a constant
that is stored into the bag.  Should not be accessed after the bag
is deleted.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fget_005ffriendly_005fname-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_get_friendly_name</h4>
<a name="gnutls_005fpkcs12_005fbag_005fget_005ffriendly_005fname"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fget_005ffriendly_005fname"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_get_friendly_name</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, int <var>indx</var>, char ** <var>name</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>indx</var>: The bag&rsquo;s element to add the id
</p>
<p><var>name</var>: will hold a pointer to the name (to be treated as const)
</p>
<p>This function will return the friendly name, of the specified bag
element.  The key ID is usually used to distinguish the local
private key and the certificate pair.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value. or a negative error code on error.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fget_005fkey_005fid-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_get_key_id</h4>
<a name="gnutls_005fpkcs12_005fbag_005fget_005fkey_005fid"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fget_005fkey_005fid"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_get_key_id</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, int <var>indx</var>, gnutls_datum_t * <var>id</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>indx</var>: The bag&rsquo;s element to add the id
</p>
<p><var>id</var>: where the ID will be copied (to be treated as const)
</p>
<p>This function will return the key ID, of the specified bag element.
The key ID is usually used to distinguish the local private key and
the certificate pair.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value. or a negative error code on error.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fget_005ftype-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_get_type</h4>
<a name="gnutls_005fpkcs12_005fbag_005fget_005ftype"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fget_005ftype"></a>Function: <em>gnutls_pkcs12_bag_type_t</em> <strong>gnutls_pkcs12_bag_get_type</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, int <var>indx</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>indx</var>: The element of the bag to get the type
</p>
<p>This function will return the bag&rsquo;s type.
</p>
<p><strong>Returns:</strong> One of the <code>gnutls_pkcs12_bag_type_t</code>  enumerations.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005finit-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_init</h4>
<a name="gnutls_005fpkcs12_005fbag_005finit"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005finit"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_init</strong> <em>(gnutls_pkcs12_bag_t * <var>bag</var>)</em></dt>
<dd><p><var>bag</var>: The structure to be initialized
</p>
<p>This function will initialize a PKCS12 bag structure. PKCS12 Bags
usually contain private keys, lists of X.509 Certificates and X.509
Certificate revocation lists.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fset_005fcrl-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_set_crl</h4>
<a name="gnutls_005fpkcs12_005fbag_005fset_005fcrl"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fset_005fcrl"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_set_crl</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, gnutls_x509_crl_t <var>crl</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>crl</var>: the CRL to be copied.
</p>
<p>This function will insert the given CRL into the
bag. This is just a wrapper over <code>gnutls_pkcs12_bag_set_data()</code> .
</p>
<p><strong>Returns:</strong> the index of the added bag on success, or a negative error code
on failure.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fset_005fcrt-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_set_crt</h4>
<a name="gnutls_005fpkcs12_005fbag_005fset_005fcrt"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fset_005fcrt"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_set_crt</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, gnutls_x509_crt_t <var>crt</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>crt</var>: the certificate to be copied.
</p>
<p>This function will insert the given certificate into the
bag. This is just a wrapper over <code>gnutls_pkcs12_bag_set_data()</code> .
</p>
<p><strong>Returns:</strong> the index of the added bag on success, or a negative
value on failure.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fset_005fdata-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_set_data</h4>
<a name="gnutls_005fpkcs12_005fbag_005fset_005fdata"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fset_005fdata"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_set_data</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, gnutls_pkcs12_bag_type_t <var>type</var>, const gnutls_datum_t * <var>data</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>type</var>: The data&rsquo;s type
</p>
<p><var>data</var>: the data to be copied.
</p>
<p>This function will insert the given data of the given type into
the bag.
</p>
<p><strong>Returns:</strong> the index of the added bag on success, or a negative
value on error.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fset_005ffriendly_005fname-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_set_friendly_name</h4>
<a name="gnutls_005fpkcs12_005fbag_005fset_005ffriendly_005fname"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fset_005ffriendly_005fname"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_set_friendly_name</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, int <var>indx</var>, const char * <var>name</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>indx</var>: The bag&rsquo;s element to add the id
</p>
<p><var>name</var>: the name
</p>
<p>This function will add the given key friendly name, to the
specified, by the index, bag element. The name will be encoded as
a &rsquo;Friendly name&rsquo; bag attribute, which is usually used to set a
user name to the local private key and the certificate pair.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value. or a negative error code on error.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fbag_005fset_005fkey_005fid-1"></a>
<h4 class="subheading">gnutls_pkcs12_bag_set_key_id</h4>
<a name="gnutls_005fpkcs12_005fbag_005fset_005fkey_005fid"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fbag_005fset_005fkey_005fid"></a>Function: <em>int</em> <strong>gnutls_pkcs12_bag_set_key_id</strong> <em>(gnutls_pkcs12_bag_t <var>bag</var>, int <var>indx</var>, const gnutls_datum_t * <var>id</var>)</em></dt>
<dd><p><var>bag</var>: The bag
</p>
<p><var>indx</var>: The bag&rsquo;s element to add the id
</p>
<p><var>id</var>: the ID
</p>
<p>This function will add the given key ID, to the specified, by the
index, bag element. The key ID will be encoded as a &rsquo;Local key
identifier&rsquo; bag attribute, which is usually used to distinguish
the local private key and the certificate pair.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value. or a negative error code on error.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fdeinit-1"></a>
<h4 class="subheading">gnutls_pkcs12_deinit</h4>
<a name="gnutls_005fpkcs12_005fdeinit"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fdeinit"></a>Function: <em>void</em> <strong>gnutls_pkcs12_deinit</strong> <em>(gnutls_pkcs12_t <var>pkcs12</var>)</em></dt>
<dd><p><var>pkcs12</var>: The structure to be initialized
</p>
<p>This function will deinitialize a PKCS12 structure.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fexport-1"></a>
<h4 class="subheading">gnutls_pkcs12_export</h4>
<a name="gnutls_005fpkcs12_005fexport"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fexport"></a>Function: <em>int</em> <strong>gnutls_pkcs12_export</strong> <em>(gnutls_pkcs12_t <var>pkcs12</var>, gnutls_x509_crt_fmt_t <var>format</var>, void * <var>output_data</var>, size_t * <var>output_data_size</var>)</em></dt>
<dd><p><var>pkcs12</var>: Holds the pkcs12 structure
</p>
<p><var>format</var>: the format of output params. One of PEM or DER.
</p>
<p><var>output_data</var>: will contain a structure PEM or DER encoded
</p>
<p><var>output_data_size</var>: holds the size of output_data (and will be
replaced by the actual size of parameters)
</p>
<p>This function will export the pkcs12 structure to DER or PEM format.
</p>
<p>If the buffer provided is not long enough to hold the output, then
*output_data_size will be updated and GNUTLS_E_SHORT_MEMORY_BUFFER
will be returned.
</p>
<p>If the structure is PEM encoded, it will have a header
of &quot;BEGIN PKCS12&quot;.
</p>
<p><strong>Returns:</strong> In case of failure a negative error code will be
returned, and 0 on success.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fexport2-1"></a>
<h4 class="subheading">gnutls_pkcs12_export2</h4>
<a name="gnutls_005fpkcs12_005fexport2"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fexport2"></a>Function: <em>int</em> <strong>gnutls_pkcs12_export2</strong> <em>(gnutls_pkcs12_t <var>pkcs12</var>, gnutls_x509_crt_fmt_t <var>format</var>, gnutls_datum_t * <var>out</var>)</em></dt>
<dd><p><var>pkcs12</var>: Holds the pkcs12 structure
</p>
<p><var>format</var>: the format of output params. One of PEM or DER.
</p>
<p><var>out</var>: will contain a structure PEM or DER encoded
</p>
<p>This function will export the pkcs12 structure to DER or PEM format.
</p>
<p>The output buffer is allocated using <code>gnutls_malloc()</code> .
</p>
<p>If the structure is PEM encoded, it will have a header
of &quot;BEGIN PKCS12&quot;.
</p>
<p><strong>Returns:</strong> In case of failure a negative error code will be
returned, and 0 on success.
</p>
<p><strong>Since:</strong> 3.1.3
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fgenerate_005fmac-1"></a>
<h4 class="subheading">gnutls_pkcs12_generate_mac</h4>
<a name="gnutls_005fpkcs12_005fgenerate_005fmac"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fgenerate_005fmac"></a>Function: <em>int</em> <strong>gnutls_pkcs12_generate_mac</strong> <em>(gnutls_pkcs12_t <var>pkcs12</var>, const char * <var>pass</var>)</em></dt>
<dd><p><var>pkcs12</var>: should contain a gnutls_pkcs12_t structure
</p>
<p><var>pass</var>: The password for the MAC
</p>
<p>This function will generate a MAC for the PKCS12 structure.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fget_005fbag-1"></a>
<h4 class="subheading">gnutls_pkcs12_get_bag</h4>
<a name="gnutls_005fpkcs12_005fget_005fbag"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fget_005fbag"></a>Function: <em>int</em> <strong>gnutls_pkcs12_get_bag</strong> <em>(gnutls_pkcs12_t <var>pkcs12</var>, int <var>indx</var>, gnutls_pkcs12_bag_t <var>bag</var>)</em></dt>
<dd><p><var>pkcs12</var>: should contain a gnutls_pkcs12_t structure
</p>
<p><var>indx</var>: contains the index of the bag to extract
</p>
<p><var>bag</var>: An initialized bag, where the contents of the bag will be copied
</p>
<p>This function will return a Bag from the PKCS12 structure.
</p>
<p>After the last Bag has been read
<code>GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE</code>  will be returned.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fimport-1"></a>
<h4 class="subheading">gnutls_pkcs12_import</h4>
<a name="gnutls_005fpkcs12_005fimport"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fimport"></a>Function: <em>int</em> <strong>gnutls_pkcs12_import</strong> <em>(gnutls_pkcs12_t <var>pkcs12</var>, const gnutls_datum_t * <var>data</var>, gnutls_x509_crt_fmt_t <var>format</var>, unsigned int <var>flags</var>)</em></dt>
<dd><p><var>pkcs12</var>: The structure to store the parsed PKCS12.
</p>
<p><var>data</var>: The DER or PEM encoded PKCS12.
</p>
<p><var>format</var>: One of DER or PEM
</p>
<p><var>flags</var>: an ORed sequence of gnutls_privkey_pkcs8_flags
</p>
<p>This function will convert the given DER or PEM encoded PKCS12
to the native gnutls_pkcs12_t format. The output will be stored in &rsquo;pkcs12&rsquo;.
</p>
<p>If the PKCS12 is PEM encoded it should have a header of &quot;PKCS12&quot;.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005finit-1"></a>
<h4 class="subheading">gnutls_pkcs12_init</h4>
<a name="gnutls_005fpkcs12_005finit"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005finit"></a>Function: <em>int</em> <strong>gnutls_pkcs12_init</strong> <em>(gnutls_pkcs12_t * <var>pkcs12</var>)</em></dt>
<dd><p><var>pkcs12</var>: The structure to be initialized
</p>
<p>This function will initialize a PKCS12 structure. PKCS12 structures
usually contain lists of X.509 Certificates and X.509 Certificate
revocation lists.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fset_005fbag-1"></a>
<h4 class="subheading">gnutls_pkcs12_set_bag</h4>
<a name="gnutls_005fpkcs12_005fset_005fbag"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fset_005fbag"></a>Function: <em>int</em> <strong>gnutls_pkcs12_set_bag</strong> <em>(gnutls_pkcs12_t <var>pkcs12</var>, gnutls_pkcs12_bag_t <var>bag</var>)</em></dt>
<dd><p><var>pkcs12</var>: should contain a gnutls_pkcs12_t structure
</p>
<p><var>bag</var>: An initialized bag
</p>
<p>This function will insert a Bag into the PKCS12 structure.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value.
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fsimple_005fparse-1"></a>
<h4 class="subheading">gnutls_pkcs12_simple_parse</h4>
<a name="gnutls_005fpkcs12_005fsimple_005fparse"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fsimple_005fparse-1"></a>Function: <em>int</em> <strong>gnutls_pkcs12_simple_parse</strong> <em>(gnutls_pkcs12_t <var>p12</var>, const char * <var>password</var>, gnutls_x509_privkey_t * <var>key</var>, gnutls_x509_crt_t ** <var>chain</var>, unsigned int * <var>chain_len</var>, gnutls_x509_crt_t ** <var>extra_certs</var>, unsigned int * <var>extra_certs_len</var>, gnutls_x509_crl_t * <var>crl</var>, unsigned int <var>flags</var>)</em></dt>
<dd><p><var>p12</var>: the PKCS12 blob.
</p>
<p><var>password</var>: optional password used to decrypt PKCS12 blob, bags and keys.
</p>
<p><var>key</var>: a structure to store the parsed private key.
</p>
<p><var>chain</var>: the corresponding to key certificate chain (may be <code>NULL</code> )
</p>
<p><var>chain_len</var>: will be updated with the number of additional (may be <code>NULL</code> )
</p>
<p><var>extra_certs</var>: optional pointer to receive an array of additional
certificates found in the PKCS12 blob (may be <code>NULL</code> ).
</p>
<p><var>extra_certs_len</var>: will be updated with the number of additional
certs (may be <code>NULL</code> ).
</p>
<p><var>crl</var>: an optional structure to store the parsed CRL (may be <code>NULL</code> ).
</p>
<p><var>flags</var>: should be zero or one of GNUTLS_PKCS12_SP_*
</p>
<p>This function parses a PKCS12 blob in  <code>p12blob</code> and extracts the
private key, the corresponding certificate chain, any additional
certificates and a CRL.
</p>
<p>The  <code>extra_certs</code> and  <code>extra_certs_len</code> parameters are optional
and both may be set to <code>NULL</code> . If either is non-<code>NULL</code> , then both must
be set. The value for  <code>extra_certs</code> is allocated
using <code>gnutls_malloc()</code> .
</p>
<p>Encrypted PKCS12 bags and PKCS8 private keys are supported, but
only with password based security and the same password for all
operations.
</p>
<p>Note that a PKCS12 file may contain many keys and/or certificates,
and there is no way to identify which key/certificate pair you want.
For this reason this function is useful for PKCS12 files that contain 
only one key/certificate pair and/or one CRL.
</p>
<p>If the provided structure has encrypted fields but no password
is provided then this function returns <code>GNUTLS_E_DECRYPTION_FAILED</code> .
</p>
<p>Note that normally the chain constructed does not include self signed
certificates, to comply with TLS&rsquo; requirements. If, however, the flag 
<code>GNUTLS_PKCS12_SP_INCLUDE_SELF_SIGNED</code>  is specified then
self signed certificates will be included in the chain.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value.
</p>
<p><strong>Since:</strong> 3.1.0
</p></dd></dl>

<a name="gnutls_005fpkcs12_005fverify_005fmac-1"></a>
<h4 class="subheading">gnutls_pkcs12_verify_mac</h4>
<a name="gnutls_005fpkcs12_005fverify_005fmac"></a><dl>
<dt><a name="index-gnutls_005fpkcs12_005fverify_005fmac"></a>Function: <em>int</em> <strong>gnutls_pkcs12_verify_mac</strong> <em>(gnutls_pkcs12_t <var>pkcs12</var>, const char * <var>pass</var>)</em></dt>
<dd><p><var>pkcs12</var>: should contain a gnutls_pkcs12_t structure
</p>
<p><var>pass</var>: The password for the MAC
</p>
<p>This function will verify the MAC for the PKCS12 structure.
</p>
<p><strong>Returns:</strong> On success, <code>GNUTLS_E_SUCCESS</code>  (0) is returned, otherwise a
negative error value.
</p></dd></dl>


<hr>
<div class="header">
<p>
Next: <a href="PKCS-11-API.html#PKCS-11-API" accesskey="n" rel="next">PKCS 11 API</a>, Previous: <a href="OpenPGP-API.html#OpenPGP-API" accesskey="p" rel="prev">OpenPGP API</a>, Up: <a href="API-reference.html#API-reference" accesskey="u" rel="up">API reference</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Function-and-Data-Index.html#Function-and-Data-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>