PEM_read_bio_PrivateKey.pod 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. =pod
  2. =head1 NAME
  3. pem_password_cb,
  4. PEM_read_bio_PrivateKey, PEM_read_PrivateKey, PEM_write_bio_PrivateKey,
  5. PEM_write_bio_PrivateKey_traditional, PEM_write_PrivateKey,
  6. PEM_write_bio_PKCS8PrivateKey, PEM_write_PKCS8PrivateKey,
  7. PEM_write_bio_PKCS8PrivateKey_nid, PEM_write_PKCS8PrivateKey_nid,
  8. PEM_read_bio_PUBKEY, PEM_read_PUBKEY, PEM_write_bio_PUBKEY, PEM_write_PUBKEY,
  9. PEM_read_bio_RSAPrivateKey, PEM_read_RSAPrivateKey,
  10. PEM_write_bio_RSAPrivateKey, PEM_write_RSAPrivateKey,
  11. PEM_read_bio_RSAPublicKey, PEM_read_RSAPublicKey, PEM_write_bio_RSAPublicKey,
  12. PEM_write_RSAPublicKey, PEM_read_bio_RSA_PUBKEY, PEM_read_RSA_PUBKEY,
  13. PEM_write_bio_RSA_PUBKEY, PEM_write_RSA_PUBKEY, PEM_read_bio_DSAPrivateKey,
  14. PEM_read_DSAPrivateKey, PEM_write_bio_DSAPrivateKey, PEM_write_DSAPrivateKey,
  15. PEM_read_bio_DSA_PUBKEY, PEM_read_DSA_PUBKEY, PEM_write_bio_DSA_PUBKEY,
  16. PEM_write_DSA_PUBKEY, PEM_read_bio_Parameters, PEM_write_bio_Parameters,
  17. PEM_read_bio_DSAparams, PEM_read_DSAparams,
  18. PEM_write_bio_DSAparams, PEM_write_DSAparams, PEM_read_bio_DHparams,
  19. PEM_read_DHparams, PEM_write_bio_DHparams, PEM_write_DHparams,
  20. PEM_read_bio_X509, PEM_read_X509, PEM_write_bio_X509, PEM_write_X509,
  21. PEM_read_bio_X509_AUX, PEM_read_X509_AUX, PEM_write_bio_X509_AUX,
  22. PEM_write_X509_AUX, PEM_read_bio_X509_REQ, PEM_read_X509_REQ,
  23. PEM_write_bio_X509_REQ, PEM_write_X509_REQ, PEM_write_bio_X509_REQ_NEW,
  24. PEM_write_X509_REQ_NEW, PEM_read_bio_X509_CRL, PEM_read_X509_CRL,
  25. PEM_write_bio_X509_CRL, PEM_write_X509_CRL, PEM_read_bio_PKCS7, PEM_read_PKCS7,
  26. PEM_write_bio_PKCS7, PEM_write_PKCS7 - PEM routines
  27. =head1 SYNOPSIS
  28. #include <openssl/pem.h>
  29. typedef int pem_password_cb(char *buf, int size, int rwflag, void *u);
  30. EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x,
  31. pem_password_cb *cb, void *u);
  32. EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x,
  33. pem_password_cb *cb, void *u);
  34. int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
  35. unsigned char *kstr, int klen,
  36. pem_password_cb *cb, void *u);
  37. int PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x,
  38. const EVP_CIPHER *enc,
  39. unsigned char *kstr, int klen,
  40. pem_password_cb *cb, void *u);
  41. int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
  42. unsigned char *kstr, int klen,
  43. pem_password_cb *cb, void *u);
  44. int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
  45. char *kstr, int klen,
  46. pem_password_cb *cb, void *u);
  47. int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
  48. char *kstr, int klen,
  49. pem_password_cb *cb, void *u);
  50. int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
  51. char *kstr, int klen,
  52. pem_password_cb *cb, void *u);
  53. int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
  54. char *kstr, int klen,
  55. pem_password_cb *cb, void *u);
  56. EVP_PKEY *PEM_read_bio_PUBKEY(BIO *bp, EVP_PKEY **x,
  57. pem_password_cb *cb, void *u);
  58. EVP_PKEY *PEM_read_PUBKEY(FILE *fp, EVP_PKEY **x,
  59. pem_password_cb *cb, void *u);
  60. int PEM_write_bio_PUBKEY(BIO *bp, EVP_PKEY *x);
  61. int PEM_write_PUBKEY(FILE *fp, EVP_PKEY *x);
  62. RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **x,
  63. pem_password_cb *cb, void *u);
  64. RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **x,
  65. pem_password_cb *cb, void *u);
  66. int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
  67. unsigned char *kstr, int klen,
  68. pem_password_cb *cb, void *u);
  69. int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
  70. unsigned char *kstr, int klen,
  71. pem_password_cb *cb, void *u);
  72. RSA *PEM_read_bio_RSAPublicKey(BIO *bp, RSA **x,
  73. pem_password_cb *cb, void *u);
  74. RSA *PEM_read_RSAPublicKey(FILE *fp, RSA **x,
  75. pem_password_cb *cb, void *u);
  76. int PEM_write_bio_RSAPublicKey(BIO *bp, RSA *x);
  77. int PEM_write_RSAPublicKey(FILE *fp, RSA *x);
  78. RSA *PEM_read_bio_RSA_PUBKEY(BIO *bp, RSA **x,
  79. pem_password_cb *cb, void *u);
  80. RSA *PEM_read_RSA_PUBKEY(FILE *fp, RSA **x,
  81. pem_password_cb *cb, void *u);
  82. int PEM_write_bio_RSA_PUBKEY(BIO *bp, RSA *x);
  83. int PEM_write_RSA_PUBKEY(FILE *fp, RSA *x);
  84. DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **x,
  85. pem_password_cb *cb, void *u);
  86. DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **x,
  87. pem_password_cb *cb, void *u);
  88. int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
  89. unsigned char *kstr, int klen,
  90. pem_password_cb *cb, void *u);
  91. int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
  92. unsigned char *kstr, int klen,
  93. pem_password_cb *cb, void *u);
  94. DSA *PEM_read_bio_DSA_PUBKEY(BIO *bp, DSA **x,
  95. pem_password_cb *cb, void *u);
  96. DSA *PEM_read_DSA_PUBKEY(FILE *fp, DSA **x,
  97. pem_password_cb *cb, void *u);
  98. int PEM_write_bio_DSA_PUBKEY(BIO *bp, DSA *x);
  99. int PEM_write_DSA_PUBKEY(FILE *fp, DSA *x);
  100. EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x);
  101. int PEM_write_bio_Parameters(BIO *bp, const EVP_PKEY *x);
  102. DSA *PEM_read_bio_DSAparams(BIO *bp, DSA **x, pem_password_cb *cb, void *u);
  103. DSA *PEM_read_DSAparams(FILE *fp, DSA **x, pem_password_cb *cb, void *u);
  104. int PEM_write_bio_DSAparams(BIO *bp, DSA *x);
  105. int PEM_write_DSAparams(FILE *fp, DSA *x);
  106. DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u);
  107. DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u);
  108. int PEM_write_bio_DHparams(BIO *bp, DH *x);
  109. int PEM_write_DHparams(FILE *fp, DH *x);
  110. X509 *PEM_read_bio_X509(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
  111. X509 *PEM_read_X509(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
  112. int PEM_write_bio_X509(BIO *bp, X509 *x);
  113. int PEM_write_X509(FILE *fp, X509 *x);
  114. X509 *PEM_read_bio_X509_AUX(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
  115. X509 *PEM_read_X509_AUX(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
  116. int PEM_write_bio_X509_AUX(BIO *bp, X509 *x);
  117. int PEM_write_X509_AUX(FILE *fp, X509 *x);
  118. X509_REQ *PEM_read_bio_X509_REQ(BIO *bp, X509_REQ **x,
  119. pem_password_cb *cb, void *u);
  120. X509_REQ *PEM_read_X509_REQ(FILE *fp, X509_REQ **x,
  121. pem_password_cb *cb, void *u);
  122. int PEM_write_bio_X509_REQ(BIO *bp, X509_REQ *x);
  123. int PEM_write_X509_REQ(FILE *fp, X509_REQ *x);
  124. int PEM_write_bio_X509_REQ_NEW(BIO *bp, X509_REQ *x);
  125. int PEM_write_X509_REQ_NEW(FILE *fp, X509_REQ *x);
  126. X509_CRL *PEM_read_bio_X509_CRL(BIO *bp, X509_CRL **x,
  127. pem_password_cb *cb, void *u);
  128. X509_CRL *PEM_read_X509_CRL(FILE *fp, X509_CRL **x,
  129. pem_password_cb *cb, void *u);
  130. int PEM_write_bio_X509_CRL(BIO *bp, X509_CRL *x);
  131. int PEM_write_X509_CRL(FILE *fp, X509_CRL *x);
  132. PKCS7 *PEM_read_bio_PKCS7(BIO *bp, PKCS7 **x, pem_password_cb *cb, void *u);
  133. PKCS7 *PEM_read_PKCS7(FILE *fp, PKCS7 **x, pem_password_cb *cb, void *u);
  134. int PEM_write_bio_PKCS7(BIO *bp, PKCS7 *x);
  135. int PEM_write_PKCS7(FILE *fp, PKCS7 *x);
  136. =head1 DESCRIPTION
  137. The PEM functions read or write structures in PEM format. In
  138. this sense PEM format is simply base64 encoded data surrounded
  139. by header lines.
  140. For more details about the meaning of arguments see the
  141. B<PEM FUNCTION ARGUMENTS> section.
  142. Each operation has four functions associated with it. For
  143. brevity the term "B<TYPE> functions" will be used below to collectively
  144. refer to the PEM_read_bio_TYPE(), PEM_read_TYPE(),
  145. PEM_write_bio_TYPE(), and PEM_write_TYPE() functions.
  146. The B<PrivateKey> functions read or write a private key in PEM format using an
  147. EVP_PKEY structure. The write routines use PKCS#8 private key format and are
  148. equivalent to PEM_write_bio_PKCS8PrivateKey().The read functions transparently
  149. handle traditional and PKCS#8 format encrypted and unencrypted keys.
  150. PEM_write_bio_PrivateKey_traditional() writes out a private key in the
  151. "traditional" format with a simple private key marker and should only
  152. be used for compatibility with legacy programs.
  153. PEM_write_bio_PKCS8PrivateKey() and PEM_write_PKCS8PrivateKey() write a private
  154. key in an EVP_PKEY structure in PKCS#8 EncryptedPrivateKeyInfo format using
  155. PKCS#5 v2.0 password based encryption algorithms. The B<cipher> argument
  156. specifies the encryption algorithm to use: unlike some other PEM routines the
  157. encryption is applied at the PKCS#8 level and not in the PEM headers. If
  158. B<cipher> is NULL then no encryption is used and a PKCS#8 PrivateKeyInfo
  159. structure is used instead.
  160. PEM_write_bio_PKCS8PrivateKey_nid() and PEM_write_PKCS8PrivateKey_nid()
  161. also write out a private key as a PKCS#8 EncryptedPrivateKeyInfo however
  162. it uses PKCS#5 v1.5 or PKCS#12 encryption algorithms instead. The algorithm
  163. to use is specified in the B<nid> parameter and should be the NID of the
  164. corresponding OBJECT IDENTIFIER (see NOTES section).
  165. The B<PUBKEY> functions process a public key using an EVP_PKEY
  166. structure. The public key is encoded as a SubjectPublicKeyInfo
  167. structure.
  168. The B<RSAPrivateKey> functions process an RSA private key using an
  169. RSA structure. The write routines uses traditional format. The read
  170. routines handles the same formats as the B<PrivateKey>
  171. functions but an error occurs if the private key is not RSA.
  172. The B<RSAPublicKey> functions process an RSA public key using an
  173. RSA structure. The public key is encoded using a PKCS#1 RSAPublicKey
  174. structure.
  175. The B<RSA_PUBKEY> functions also process an RSA public key using
  176. an RSA structure. However, the public key is encoded using a
  177. SubjectPublicKeyInfo structure and an error occurs if the public
  178. key is not RSA.
  179. The B<DSAPrivateKey> functions process a DSA private key using a
  180. DSA structure. The write routines uses traditional format. The read
  181. routines handles the same formats as the B<PrivateKey>
  182. functions but an error occurs if the private key is not DSA.
  183. The B<DSA_PUBKEY> functions process a DSA public key using
  184. a DSA structure. The public key is encoded using a
  185. SubjectPublicKeyInfo structure and an error occurs if the public
  186. key is not DSA.
  187. The B<Parameters> functions read or write key parameters in PEM format using
  188. an EVP_PKEY structure. The encoding depends on the type of key; for DSA key
  189. parameters, it will be a Dss-Parms structure as defined in RFC2459, and for DH
  190. key parameters, it will be a PKCS#3 DHparameter structure. I<These functions
  191. only exist for the B<BIO> type>.
  192. The B<DSAparams> functions process DSA parameters using a DSA
  193. structure. The parameters are encoded using a Dss-Parms structure
  194. as defined in RFC2459.
  195. The B<DHparams> functions process DH parameters using a DH
  196. structure. The parameters are encoded using a PKCS#3 DHparameter
  197. structure.
  198. The B<X509> functions process an X509 certificate using an X509
  199. structure. They will also process a trusted X509 certificate but
  200. any trust settings are discarded.
  201. The B<X509_AUX> functions process a trusted X509 certificate using
  202. an X509 structure.
  203. The B<X509_REQ> and B<X509_REQ_NEW> functions process a PKCS#10
  204. certificate request using an X509_REQ structure. The B<X509_REQ>
  205. write functions use B<CERTIFICATE REQUEST> in the header whereas
  206. the B<X509_REQ_NEW> functions use B<NEW CERTIFICATE REQUEST>
  207. (as required by some CAs). The B<X509_REQ> read functions will
  208. handle either form so there are no B<X509_REQ_NEW> read functions.
  209. The B<X509_CRL> functions process an X509 CRL using an X509_CRL
  210. structure.
  211. The B<PKCS7> functions process a PKCS#7 ContentInfo using a PKCS7
  212. structure.
  213. =head1 PEM FUNCTION ARGUMENTS
  214. The PEM functions have many common arguments.
  215. The B<bp> BIO parameter (if present) specifies the BIO to read from
  216. or write to.
  217. The B<fp> FILE parameter (if present) specifies the FILE pointer to
  218. read from or write to.
  219. The PEM read functions all take an argument B<TYPE **x> and return
  220. a B<TYPE *> pointer. Where B<TYPE> is whatever structure the function
  221. uses. If B<x> is NULL then the parameter is ignored. If B<x> is not
  222. NULL but B<*x> is NULL then the structure returned will be written
  223. to B<*x>. If neither B<x> nor B<*x> is NULL then an attempt is made
  224. to reuse the structure at B<*x> (but see BUGS and EXAMPLES sections).
  225. Irrespective of the value of B<x> a pointer to the structure is always
  226. returned (or NULL if an error occurred).
  227. The PEM functions which write private keys take an B<enc> parameter
  228. which specifies the encryption algorithm to use, encryption is done
  229. at the PEM level. If this parameter is set to NULL then the private
  230. key is written in unencrypted form.
  231. The B<cb> argument is the callback to use when querying for the pass
  232. phrase used for encrypted PEM structures (normally only private keys).
  233. For the PEM write routines if the B<kstr> parameter is not NULL then
  234. B<klen> bytes at B<kstr> are used as the passphrase and B<cb> is
  235. ignored.
  236. If the B<cb> parameters is set to NULL and the B<u> parameter is not
  237. NULL then the B<u> parameter is interpreted as a null terminated string
  238. to use as the passphrase. If both B<cb> and B<u> are NULL then the
  239. default callback routine is used which will typically prompt for the
  240. passphrase on the current terminal with echoing turned off.
  241. The default passphrase callback is sometimes inappropriate (for example
  242. in a GUI application) so an alternative can be supplied. The callback
  243. routine has the following form:
  244. int cb(char *buf, int size, int rwflag, void *u);
  245. B<buf> is the buffer to write the passphrase to. B<size> is the maximum
  246. length of the passphrase (i.e. the size of buf). B<rwflag> is a flag
  247. which is set to 0 when reading and 1 when writing. A typical routine
  248. will ask the user to verify the passphrase (for example by prompting
  249. for it twice) if B<rwflag> is 1. The B<u> parameter has the same
  250. value as the B<u> parameter passed to the PEM routine. It allows
  251. arbitrary data to be passed to the callback by the application
  252. (for example a window handle in a GUI application). The callback
  253. B<must> return the number of characters in the passphrase or -1 if
  254. an error occurred.
  255. =head1 NOTES
  256. The old B<PrivateKey> write routines are retained for compatibility.
  257. New applications should write private keys using the
  258. PEM_write_bio_PKCS8PrivateKey() or PEM_write_PKCS8PrivateKey() routines
  259. because they are more secure (they use an iteration count of 2048 whereas
  260. the traditional routines use a count of 1) unless compatibility with older
  261. versions of OpenSSL is important.
  262. The B<PrivateKey> read routines can be used in all applications because
  263. they handle all formats transparently.
  264. A frequent cause of problems is attempting to use the PEM routines like
  265. this:
  266. X509 *x;
  267. PEM_read_bio_X509(bp, &x, 0, NULL);
  268. this is a bug because an attempt will be made to reuse the data at B<x>
  269. which is an uninitialised pointer.
  270. These functions make no assumption regarding the pass phrase received from the
  271. password callback.
  272. It will simply be treated as a byte sequence.
  273. =head1 PEM ENCRYPTION FORMAT
  274. These old B<PrivateKey> routines use a non standard technique for encryption.
  275. The private key (or other data) takes the following form:
  276. -----BEGIN RSA PRIVATE KEY-----
  277. Proc-Type: 4,ENCRYPTED
  278. DEK-Info: DES-EDE3-CBC,3F17F5316E2BAC89
  279. ...base64 encoded data...
  280. -----END RSA PRIVATE KEY-----
  281. The line beginning with I<Proc-Type> contains the version and the
  282. protection on the encapsulated data. The line beginning I<DEK-Info>
  283. contains two comma separated values: the encryption algorithm name as
  284. used by EVP_get_cipherbyname() and an initialization vector used by the
  285. cipher encoded as a set of hexadecimal digits. After those two lines is
  286. the base64-encoded encrypted data.
  287. The encryption key is derived using EVP_BytesToKey(). The cipher's
  288. initialization vector is passed to EVP_BytesToKey() as the B<salt>
  289. parameter. Internally, B<PKCS5_SALT_LEN> bytes of the salt are used
  290. (regardless of the size of the initialization vector). The user's
  291. password is passed to EVP_BytesToKey() using the B<data> and B<datal>
  292. parameters. Finally, the library uses an iteration count of 1 for
  293. EVP_BytesToKey().
  294. The B<key> derived by EVP_BytesToKey() along with the original initialization
  295. vector is then used to decrypt the encrypted data. The B<iv> produced by
  296. EVP_BytesToKey() is not utilized or needed, and NULL should be passed to
  297. the function.
  298. The pseudo code to derive the key would look similar to:
  299. EVP_CIPHER* cipher = EVP_des_ede3_cbc();
  300. EVP_MD* md = EVP_md5();
  301. unsigned int nkey = EVP_CIPHER_key_length(cipher);
  302. unsigned int niv = EVP_CIPHER_iv_length(cipher);
  303. unsigned char key[nkey];
  304. unsigned char iv[niv];
  305. memcpy(iv, HexToBin("3F17F5316E2BAC89"), niv);
  306. rc = EVP_BytesToKey(cipher, md, iv /*salt*/, pword, plen, 1, key, NULL /*iv*/);
  307. if (rc != nkey)
  308. /* Error */
  309. /* On success, use key and iv to initialize the cipher */
  310. =head1 BUGS
  311. The PEM read routines in some versions of OpenSSL will not correctly reuse
  312. an existing structure. Therefore, the following:
  313. PEM_read_bio_X509(bp, &x, 0, NULL);
  314. where B<x> already contains a valid certificate, may not work, whereas:
  315. X509_free(x);
  316. x = PEM_read_bio_X509(bp, NULL, 0, NULL);
  317. is guaranteed to work.
  318. =head1 RETURN VALUES
  319. The read routines return either a pointer to the structure read or NULL
  320. if an error occurred.
  321. The write routines return 1 for success or 0 for failure.
  322. =head1 EXAMPLES
  323. Although the PEM routines take several arguments in almost all applications
  324. most of them are set to 0 or NULL.
  325. Read a certificate in PEM format from a BIO:
  326. X509 *x;
  327. x = PEM_read_bio_X509(bp, NULL, 0, NULL);
  328. if (x == NULL)
  329. /* Error */
  330. Alternative method:
  331. X509 *x = NULL;
  332. if (!PEM_read_bio_X509(bp, &x, 0, NULL))
  333. /* Error */
  334. Write a certificate to a BIO:
  335. if (!PEM_write_bio_X509(bp, x))
  336. /* Error */
  337. Write a private key (using traditional format) to a BIO using
  338. triple DES encryption, the pass phrase is prompted for:
  339. if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, NULL))
  340. /* Error */
  341. Write a private key (using PKCS#8 format) to a BIO using triple
  342. DES encryption, using the pass phrase "hello":
  343. if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(),
  344. NULL, 0, 0, "hello"))
  345. /* Error */
  346. Read a private key from a BIO using a pass phrase callback:
  347. key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key");
  348. if (key == NULL)
  349. /* Error */
  350. Skeleton pass phrase callback:
  351. int pass_cb(char *buf, int size, int rwflag, void *u)
  352. {
  353. /* We'd probably do something else if 'rwflag' is 1 */
  354. printf("Enter pass phrase for \"%s\"\n", (char *)u);
  355. /* get pass phrase, length 'len' into 'tmp' */
  356. char *tmp = "hello";
  357. if (tmp == NULL) /* An error occurred */
  358. return -1;
  359. size_t len = strlen(tmp);
  360. if (len > size)
  361. len = size;
  362. memcpy(buf, tmp, len);
  363. return len;
  364. }
  365. =head1 SEE ALSO
  366. L<EVP_EncryptInit(3)>, L<EVP_BytesToKey(3)>,
  367. L<passphrase-encoding(7)>
  368. =head1 HISTORY
  369. The old Netscape certificate sequences were no longer documented
  370. in OpenSSL 1.1.0; applications should use the PKCS7 standard instead
  371. as they will be formally deprecated in a future releases.
  372. =head1 COPYRIGHT
  373. Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
  374. Licensed under the OpenSSL license (the "License"). You may not use
  375. this file except in compliance with the License. You can obtain a copy
  376. in the file LICENSE in the source distribution or at
  377. L<https://www.openssl.org/source/license.html>.
  378. =cut