openssl-rsautl.pod.in 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. =pod
  2. {- OpenSSL::safe::output_do_not_edit_headers(); -}
  3. =head1 NAME
  4. openssl-rsautl - RSA command
  5. =head1 SYNOPSIS
  6. B<openssl> B<rsautl>
  7. [B<-help>]
  8. [B<-in> I<file>]
  9. [B<-passin> I<arg>]
  10. [B<-rev>]
  11. [B<-out> I<file>]
  12. [B<-inkey> I<filename>|I<uri>]
  13. [B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE>]
  14. [B<-pubin>]
  15. [B<-certin>]
  16. [B<-sign>]
  17. [B<-verify>]
  18. [B<-encrypt>]
  19. [B<-decrypt>]
  20. [B<-pkcs>]
  21. [B<-x931>]
  22. [B<-oaep>]
  23. [B<-raw>]
  24. [B<-hexdump>]
  25. [B<-asn1parse>]
  26. {- $OpenSSL::safe::opt_engine_synopsis -}{- $OpenSSL::safe::opt_r_synopsis -}
  27. {- $OpenSSL::safe::opt_provider_synopsis -}
  28. =head1 DESCRIPTION
  29. This command has been deprecated.
  30. The L<openssl-pkeyutl(1)> command should be used instead.
  31. This command can be used to sign, verify, encrypt and decrypt
  32. data using the RSA algorithm.
  33. =head1 OPTIONS
  34. =over 4
  35. =item B<-help>
  36. Print out a usage message.
  37. =item B<-in> I<filename>
  38. This specifies the input filename to read data from or standard input
  39. if this option is not specified.
  40. =item B<-passin> I<arg>
  41. The passphrase used in the output file.
  42. See see L<openssl-passphrase-options(1)>.
  43. =item B<-rev>
  44. Reverse the order of the input.
  45. =item B<-out> I<filename>
  46. Specifies the output filename to write to or standard output by
  47. default.
  48. =item B<-inkey> I<filename>|I<uri>
  49. The input key, by default it should be an RSA private key.
  50. =item B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE>
  51. The key format; unspecified by default.
  52. See L<openssl-format-options(1)> for details.
  53. =item B<-pubin>
  54. By default a private key is read from the key input.
  55. With this option a public key is read instead.
  56. If the input contains no public key but a private key, its public part is used.
  57. =item B<-certin>
  58. The input is a certificate containing an RSA public key.
  59. =item B<-sign>
  60. Sign the input data and output the signed result. This requires
  61. an RSA private key.
  62. =item B<-verify>
  63. Verify the input data and output the recovered data.
  64. =item B<-encrypt>
  65. Encrypt the input data using an RSA public key.
  66. =item B<-decrypt>
  67. Decrypt the input data using an RSA private key.
  68. =item B<-pkcs>, B<-oaep>, B<-x931>, B<-raw>
  69. The padding to use: PKCS#1 v1.5 (the default), PKCS#1 OAEP,
  70. ANSI X9.31, or no padding, respectively.
  71. For signatures, only B<-pkcs> and B<-raw> can be used.
  72. Note: because of protection against Bleichenbacher attacks, decryption
  73. using PKCS#1 v1.5 mode will not return errors in case padding check failed.
  74. Use B<-raw> and inspect the returned value manually to check if the
  75. padding is correct.
  76. =item B<-hexdump>
  77. Hex dump the output data.
  78. =item B<-asn1parse>
  79. Parse the ASN.1 output data, this is useful when combined with the
  80. B<-verify> option.
  81. {- $OpenSSL::safe::opt_engine_item -}
  82. {- $OpenSSL::safe::opt_r_item -}
  83. {- $OpenSSL::safe::opt_provider_item -}
  84. =back
  85. =head1 NOTES
  86. Since this command uses the RSA algorithm directly, it can only be
  87. used to sign or verify small pieces of data.
  88. =head1 EXAMPLES
  89. Examples equivalent to these can be found in the documentation for the
  90. non-deprecated L<openssl-pkeyutl(1)> command.
  91. Sign some data using a private key:
  92. openssl rsautl -sign -in file -inkey key.pem -out sig
  93. Recover the signed data
  94. openssl rsautl -verify -in sig -inkey key.pem
  95. Examine the raw signed data:
  96. openssl rsautl -verify -in sig -inkey key.pem -raw -hexdump
  97. 0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  98. 0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  99. 0020 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  100. 0030 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  101. 0040 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  102. 0050 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  103. 0060 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
  104. 0070 - ff ff ff ff 00 68 65 6c-6c 6f 20 77 6f 72 6c 64 .....hello world
  105. The PKCS#1 block formatting is evident from this. If this was done using
  106. encrypt and decrypt the block would have been of type 2 (the second byte)
  107. and random padding data visible instead of the 0xff bytes.
  108. It is possible to analyse the signature of certificates using this
  109. command in conjunction with L<openssl-asn1parse(1)>. Consider the self signed
  110. example in F<certs/pca-cert.pem>. Running L<openssl-asn1parse(1)> as follows
  111. yields:
  112. openssl asn1parse -in pca-cert.pem
  113. 0:d=0 hl=4 l= 742 cons: SEQUENCE
  114. 4:d=1 hl=4 l= 591 cons: SEQUENCE
  115. 8:d=2 hl=2 l= 3 cons: cont [ 0 ]
  116. 10:d=3 hl=2 l= 1 prim: INTEGER :02
  117. 13:d=2 hl=2 l= 1 prim: INTEGER :00
  118. 16:d=2 hl=2 l= 13 cons: SEQUENCE
  119. 18:d=3 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
  120. 29:d=3 hl=2 l= 0 prim: NULL
  121. 31:d=2 hl=2 l= 92 cons: SEQUENCE
  122. 33:d=3 hl=2 l= 11 cons: SET
  123. 35:d=4 hl=2 l= 9 cons: SEQUENCE
  124. 37:d=5 hl=2 l= 3 prim: OBJECT :countryName
  125. 42:d=5 hl=2 l= 2 prim: PRINTABLESTRING :AU
  126. ....
  127. 599:d=1 hl=2 l= 13 cons: SEQUENCE
  128. 601:d=2 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
  129. 612:d=2 hl=2 l= 0 prim: NULL
  130. 614:d=1 hl=3 l= 129 prim: BIT STRING
  131. The final BIT STRING contains the actual signature. It can be extracted with:
  132. openssl asn1parse -in pca-cert.pem -out sig -noout -strparse 614
  133. The certificate public key can be extracted with:
  134. openssl x509 -in test/testx509.pem -pubkey -noout >pubkey.pem
  135. The signature can be analysed with:
  136. openssl rsautl -in sig -verify -asn1parse -inkey pubkey.pem -pubin
  137. 0:d=0 hl=2 l= 32 cons: SEQUENCE
  138. 2:d=1 hl=2 l= 12 cons: SEQUENCE
  139. 4:d=2 hl=2 l= 8 prim: OBJECT :md5
  140. 14:d=2 hl=2 l= 0 prim: NULL
  141. 16:d=1 hl=2 l= 16 prim: OCTET STRING
  142. 0000 - f3 46 9e aa 1a 4a 73 c9-37 ea 93 00 48 25 08 b5 .F...Js.7...H%..
  143. This is the parsed version of an ASN1 DigestInfo structure. It can be seen that
  144. the digest used was md5. The actual part of the certificate that was signed can
  145. be extracted with:
  146. openssl asn1parse -in pca-cert.pem -out tbs -noout -strparse 4
  147. and its digest computed with:
  148. openssl md5 -c tbs
  149. MD5(tbs)= f3:46:9e:aa:1a:4a:73:c9:37:ea:93:00:48:25:08:b5
  150. which it can be seen agrees with the recovered value above.
  151. =head1 SEE ALSO
  152. L<openssl(1)>,
  153. L<openssl-pkeyutl(1)>,
  154. L<openssl-dgst(1)>,
  155. L<openssl-rsa(1)>,
  156. L<openssl-genrsa(1)>
  157. =head1 HISTORY
  158. This command was deprecated in OpenSSL 3.0.
  159. The B<-engine> option was deprecated in OpenSSL 3.0.
  160. =head1 COPYRIGHT
  161. Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.
  162. Licensed under the Apache License 2.0 (the "License"). You may not use
  163. this file except in compliance with the License. You can obtain a copy
  164. in the file LICENSE in the source distribution or at
  165. L<https://www.openssl.org/source/license.html>.
  166. =cut