⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pem.pod

📁 开源的ssl算法openssl,版本0.9.8H
💻 POD
📖 第 1 页 / 共 2 页
字号:
The B<DSAparams> functions process DSA parameters using a DSAstructure. The parameters are encoded using a foobar structure.The B<DHparams> functions process DH parameters using a DHstructure. The parameters are encoded using a PKCS#3 DHparameterstructure.The B<X509> functions process an X509 certificate using an X509structure. They will also process a trusted X509 certificate butany trust settings are discarded.The B<X509_AUX> functions process a trusted X509 certificate usingan X509 structure. The B<X509_REQ> and B<X509_REQ_NEW> functions process a PKCS#10certificate request using an X509_REQ structure. The B<X509_REQ>write functions use B<CERTIFICATE REQUEST> in the header whereasthe B<X509_REQ_NEW> functions use B<NEW CERTIFICATE REQUEST>(as required by some CAs). The B<X509_REQ> read functions willhandle either form so there are no B<X509_REQ_NEW> read functions.The B<X509_CRL> functions process an X509 CRL using an X509_CRLstructure.The B<PKCS7> functions process a PKCS#7 ContentInfo using a PKCS7structure.The B<NETSCAPE_CERT_SEQUENCE> functions process a Netscape CertificateSequence using a NETSCAPE_CERT_SEQUENCE structure.=head1 PEM FUNCTION ARGUMENTSThe PEM functions have many common arguments.The B<bp> BIO parameter (if present) specifies the BIO to read fromor write to.The B<fp> FILE parameter (if present) specifies the FILE pointer toread from or write to.The PEM read functions all take an argument B<TYPE **x> and returna B<TYPE *> pointer. Where B<TYPE> is whatever structure the functionuses. If B<x> is NULL then the parameter is ignored. If B<x> is notNULL but B<*x> is NULL then the structure returned will be writtento B<*x>. If neither B<x> nor B<*x> is NULL then an attempt is madeto reuse the structure at B<*x> (but see BUGS and EXAMPLES sections).Irrespective of the value of B<x> a pointer to the structure is alwaysreturned (or NULL if an error occurred).The PEM functions which write private keys take an B<enc> parameterwhich specifies the encryption algorithm to use, encryption is doneat the PEM level. If this parameter is set to NULL then the privatekey is written in unencrypted form.The B<cb> argument is the callback to use when querying for the passphrase used for encrypted PEM structures (normally only private keys).For the PEM write routines if the B<kstr> parameter is not NULL thenB<klen> bytes at B<kstr> are used as the passphrase and B<cb> isignored.If the B<cb> parameters is set to NULL and the B<u> parameter is notNULL then the B<u> parameter is interpreted as a null terminated stringto use as the passphrase. If both B<cb> and B<u> are NULL then thedefault callback routine is used which will typically prompt for thepassphrase on the current terminal with echoing turned off.The default passphrase callback is sometimes inappropriate (for examplein a GUI application) so an alternative can be supplied. The callbackroutine has the following form: int cb(char *buf, int size, int rwflag, void *u);B<buf> is the buffer to write the passphrase to. B<size> is the maximumlength of the passphrase (i.e. the size of buf). B<rwflag> is a flagwhich is set to 0 when reading and 1 when writing. A typical routinewill ask the user to verify the passphrase (for example by promptingfor it twice) if B<rwflag> is 1. The B<u> parameter has the samevalue as the B<u> parameter passed to the PEM routine. It allowsarbitrary data to be passed to the callback by the application(for example a window handle in a GUI application). The callbackB<must> return the number of characters in the passphrase or 0 ifan error occurred.=head1 EXAMPLESAlthough the PEM routines take several arguments in almost all applicationsmost of them are set to 0 or NULL.Read a certificate in PEM format from a BIO: X509 *x; x = PEM_read_bio_X509(bp, NULL, 0, NULL); if (x == NULL)	{	/* Error */	}Alternative method: X509 *x = NULL; if (!PEM_read_bio_X509(bp, &x, 0, NULL))	{	/* Error */	}Write a certificate to a BIO: if (!PEM_write_bio_X509(bp, x))	{	/* Error */	}Write an unencrypted private key to a FILE pointer: if (!PEM_write_PrivateKey(fp, key, NULL, NULL, 0, 0, NULL))	{	/* Error */	}Write a private key (using traditional format) to a BIO usingtriple DES encryption, the pass phrase is prompted for: if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, NULL))	{	/* Error */	}Write a private key (using PKCS#8 format) to a BIO using tripleDES encryption, using the pass phrase "hello": if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, "hello"))	{	/* Error */	}Read a private key from a BIO using the pass phrase "hello": key = PEM_read_bio_PrivateKey(bp, NULL, 0, "hello"); if (key == NULL)	{	/* Error */	}Read a private key from a BIO using a pass phrase callback: key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key"); if (key == NULL)	{	/* Error */	}Skeleton pass phrase callback: int pass_cb(char *buf, int size, int rwflag, void *u);	{	int len;	char *tmp;	/* We'd probably do something else if 'rwflag' is 1 */	printf("Enter pass phrase for \"%s\"\n", u);	/* get pass phrase, length 'len' into 'tmp' */	tmp = "hello";	len = strlen(tmp);	if (len <= 0) return 0;	/* if too long, truncate */	if (len > size) len = size;	memcpy(buf, tmp, len);	return len;	}=head1 NOTESThe old B<PrivateKey> write routines are retained for compatibility.New applications should write private keys using thePEM_write_bio_PKCS8PrivateKey() or PEM_write_PKCS8PrivateKey() routinesbecause they are more secure (they use an iteration count of 2048 whereasthe traditional routines use a count of 1) unless compatibility with olderversions of OpenSSL is important.The B<PrivateKey> read routines can be used in all applications becausethey handle all formats transparently.A frequent cause of problems is attempting to use the PEM routines likethis: X509 *x; PEM_read_bio_X509(bp, &x, 0, NULL);this is a bug because an attempt will be made to reuse the data at B<x>which is an uninitialised pointer.=head1 PEM ENCRYPTION FORMATThis old B<PrivateKey> routines use a non standard technique for encryption.The private key (or other data) takes the following form:  -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,3F17F5316E2BAC89 ...base64 encoded data... -----END RSA PRIVATE KEY-----The line beginning DEK-Info contains two comma separated pieces of information:the encryption algorithm name as used by EVP_get_cipherbyname() and an 8byte B<salt> encoded as a set of hexadecimal digits.After this is the base64 encoded encrypted data.The encryption key is determined using EVP_bytestokey(), using B<salt> and aniteration count of 1. The IV used is the value of B<salt> and *not* the IVreturned by EVP_bytestokey().=head1 BUGSThe PEM read routines in some versions of OpenSSL will not correctly reusean existing structure. Therefore the following: PEM_read_bio_X509(bp, &x, 0, NULL);where B<x> already contains a valid certificate, may not work, whereas:  X509_free(x); x = PEM_read_bio_X509(bp, NULL, 0, NULL);is guaranteed to work.=head1 RETURN CODESThe read routines return either a pointer to the structure read or NULLif an error occurred.The write routines return 1 for success or 0 for failure.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -