2
0

pkeyutl.pod 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. =pod
  2. =head1 NAME
  3. pkeyutl - public key algorithm utility
  4. =head1 SYNOPSIS
  5. B<openssl> B<pkeyutl>
  6. [B<-in file>]
  7. [B<-out file>]
  8. [B<-sigfile file>]
  9. [B<-inkey file>]
  10. [B<-keyform PEM|DER>]
  11. [B<-passin arg>]
  12. [B<-peerkey file>]
  13. [B<-peerform PEM|DER>]
  14. [B<-pubin>]
  15. [B<-certin>]
  16. [B<-rev>]
  17. [B<-sign>]
  18. [B<-verify>]
  19. [B<-verifyrecover>]
  20. [B<-encrypt>]
  21. [B<-decrypt>]
  22. [B<-derive>]
  23. [B<-pkeyopt opt:value>]
  24. [B<-hexdump>]
  25. [B<-asn1parse>]
  26. [B<-engine id>]
  27. =head1 DESCRIPTION
  28. The B<pkeyutl> command can be used to perform public key operations using
  29. any supported algorithm.
  30. =head1 COMMAND OPTIONS
  31. =over 4
  32. =item B<-in filename>
  33. This specifies the input filename to read data from or standard input
  34. if this option is not specified.
  35. =item B<-out filename>
  36. specifies the output filename to write to or standard output by
  37. default.
  38. =item B<-inkey file>
  39. the input key file, by default it should be a private key.
  40. =item B<-keyform PEM|DER>
  41. the key format PEM, DER or ENGINE.
  42. =item B<-passin arg>
  43. the input key password source. For more information about the format of B<arg>
  44. see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
  45. =item B<-peerkey file>
  46. the peer key file, used by key derivation (agreement) operations.
  47. =item B<-peerform PEM|DER>
  48. the peer key format PEM, DER or ENGINE.
  49. =item B<-engine id>
  50. specifying an engine (by its unique B<id> string) will cause B<pkeyutl>
  51. to attempt to obtain a functional reference to the specified engine,
  52. thus initialising it if needed. The engine will then be set as the default
  53. for all available algorithms.
  54. =item B<-pubin>
  55. the input file is a public key.
  56. =item B<-certin>
  57. the input is a certificate containing a public key.
  58. =item B<-rev>
  59. reverse the order of the input buffer. This is useful for some libraries
  60. (such as CryptoAPI) which represent the buffer in little endian format.
  61. =item B<-sign>
  62. sign the input data and output the signed result. This requires
  63. a private key.
  64. =item B<-verify>
  65. verify the input data against the signature file and indicate if the
  66. verification succeeded or failed.
  67. =item B<-verifyrecover>
  68. verify the input data and output the recovered data.
  69. =item B<-encrypt>
  70. encrypt the input data using a public key.
  71. =item B<-decrypt>
  72. decrypt the input data using a private key.
  73. =item B<-derive>
  74. derive a shared secret using the peer key.
  75. =item B<-hexdump>
  76. hex dump the output data.
  77. =item B<-asn1parse>
  78. asn1parse the output data, this is useful when combined with the
  79. B<-verifyrecover> option when an ASN1 structure is signed.
  80. =back
  81. =head1 NOTES
  82. The operations and options supported vary according to the key algorithm
  83. and its implementation. The OpenSSL operations and options are indicated below.
  84. Unless otherwise mentioned all algorithms support the B<digest:alg> option
  85. which specifies the digest in use for sign, verify and verifyrecover operations.
  86. The value B<alg> should represent a digest name as used in the
  87. EVP_get_digestbyname() function for example B<sha1>.
  88. This value is used only for sanity-checking the lengths of data passed in to
  89. the B<pkeyutl> and for creating the structures that make up the signature
  90. (e.g. B<DigestInfo> in RSASSA PKCS#1 v1.5 signatures).
  91. In case of RSA, ECDSA and DSA signatures, this utility
  92. will not perform hashing on input data but rather use the data directly as
  93. input of signature algorithm. Depending on key type, signature type and mode
  94. of padding, the maximum acceptable lengths of input data differ. In general,
  95. with RSA the signed data can't be longer than the key modulus, in case of ECDSA
  96. and DSA the data shouldn't be longer than field size, otherwise it will be
  97. silently truncated to field size.
  98. In other words, if the value of digest is B<sha1> the input should be 20 bytes
  99. long binary encoding of SHA-1 hash function output.
  100. =head1 RSA ALGORITHM
  101. The RSA algorithm supports encrypt, decrypt, sign, verify and verifyrecover
  102. operations in general. Some padding modes only support some of these
  103. operations however.
  104. =over 4
  105. =item -B<rsa_padding_mode:mode>
  106. This sets the RSA padding mode. Acceptable values for B<mode> are B<pkcs1> for
  107. PKCS#1 padding, B<sslv23> for SSLv23 padding, B<none> for no padding, B<oaep>
  108. for B<OAEP> mode, B<x931> for X9.31 mode and B<pss> for PSS.
  109. In PKCS#1 padding if the message digest is not set then the supplied data is
  110. signed or verified directly instead of using a B<DigestInfo> structure. If a
  111. digest is set then the a B<DigestInfo> structure is used and its the length
  112. must correspond to the digest type.
  113. For B<oeap> mode only encryption and decryption is supported.
  114. For B<x931> if the digest type is set it is used to format the block data
  115. otherwise the first byte is used to specify the X9.31 digest ID. Sign,
  116. verify and verifyrecover are can be performed in this mode.
  117. For B<pss> mode only sign and verify are supported and the digest type must be
  118. specified.
  119. =item B<rsa_pss_saltlen:len>
  120. For B<pss> mode only this option specifies the salt length. Two special values
  121. are supported: -1 sets the salt length to the digest length. When signing -2
  122. sets the salt length to the maximum permissible value. When verifying -2 causes
  123. the salt length to be automatically determined based on the B<PSS> block
  124. structure.
  125. =back
  126. =head1 DSA ALGORITHM
  127. The DSA algorithm supports signing and verification operations only. Currently
  128. there are no additional options other than B<digest>. Only the SHA1
  129. digest can be used and this digest is assumed by default.
  130. =head1 DH ALGORITHM
  131. The DH algorithm only supports the derivation operation and no additional
  132. options.
  133. =head1 EC ALGORITHM
  134. The EC algorithm supports sign, verify and derive operations. The sign and
  135. verify operations use ECDSA and derive uses ECDH. Currently there are no
  136. additional options other than B<digest>. Only the SHA1 digest can be used and
  137. this digest is assumed by default.
  138. =head1 EXAMPLES
  139. Sign some data using a private key:
  140. openssl pkeyutl -sign -in file -inkey key.pem -out sig
  141. Recover the signed data (e.g. if an RSA key is used):
  142. openssl pkeyutl -verifyrecover -in sig -inkey key.pem
  143. Verify the signature (e.g. a DSA key):
  144. openssl pkeyutl -verify -in file -sigfile sig -inkey key.pem
  145. Sign data using a message digest value (this is currently only valid for RSA):
  146. openssl pkeyutl -sign -in file -inkey key.pem -out sig -pkeyopt digest:sha256
  147. Derive a shared secret value:
  148. openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret
  149. =head1 SEE ALSO
  150. L<genpkey(1)|genpkey(1)>, L<pkey(1)|pkey(1)>, L<rsautl(1)|rsautl(1)>
  151. L<dgst(1)|dgst(1)>, L<rsa(1)|rsa(1)>, L<genrsa(1)|genrsa(1)>