openssl-rsautl.1ossl 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "OPENSSL-RSAUTL 1ossl"
  58. .TH OPENSSL-RSAUTL 1ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. openssl\-rsautl \- RSA command
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. \&\fBopenssl\fR \fBrsautl\fR
  68. [\fB\-help\fR]
  69. [\fB\-in\fR \fIfile\fR]
  70. [\fB\-passin\fR \fIarg\fR]
  71. [\fB\-rev\fR]
  72. [\fB\-out\fR \fIfile\fR]
  73. [\fB\-inkey\fR \fIfilename\fR|\fIuri\fR]
  74. [\fB\-keyform\fR \fBDER\fR|\fBPEM\fR|\fBP12\fR|\fBENGINE\fR]
  75. [\fB\-pubin\fR]
  76. [\fB\-certin\fR]
  77. [\fB\-sign\fR]
  78. [\fB\-verify\fR]
  79. [\fB\-encrypt\fR]
  80. [\fB\-decrypt\fR]
  81. [\fB\-pkcs\fR]
  82. [\fB\-x931\fR]
  83. [\fB\-oaep\fR]
  84. [\fB\-raw\fR]
  85. [\fB\-hexdump\fR]
  86. [\fB\-asn1parse\fR]
  87. [\fB\-engine\fR \fIid\fR]
  88. [\fB\-rand\fR \fIfiles\fR]
  89. [\fB\-writerand\fR \fIfile\fR]
  90. [\fB\-provider\fR \fIname\fR]
  91. [\fB\-provider\-path\fR \fIpath\fR]
  92. [\fB\-propquery\fR \fIpropq\fR]
  93. .SH DESCRIPTION
  94. .IX Header "DESCRIPTION"
  95. This command has been deprecated.
  96. The \fBopenssl\-pkeyutl\fR\|(1) command should be used instead.
  97. .PP
  98. This command can be used to sign, verify, encrypt and decrypt
  99. data using the RSA algorithm.
  100. .SH OPTIONS
  101. .IX Header "OPTIONS"
  102. .IP \fB\-help\fR 4
  103. .IX Item "-help"
  104. Print out a usage message.
  105. .IP "\fB\-in\fR \fIfilename\fR" 4
  106. .IX Item "-in filename"
  107. This specifies the input filename to read data from or standard input
  108. if this option is not specified.
  109. .IP "\fB\-passin\fR \fIarg\fR" 4
  110. .IX Item "-passin arg"
  111. The passphrase used in the output file.
  112. See see \fBopenssl\-passphrase\-options\fR\|(1).
  113. .IP \fB\-rev\fR 4
  114. .IX Item "-rev"
  115. Reverse the order of the input.
  116. .IP "\fB\-out\fR \fIfilename\fR" 4
  117. .IX Item "-out filename"
  118. Specifies the output filename to write to or standard output by
  119. default.
  120. .IP "\fB\-inkey\fR \fIfilename\fR|\fIuri\fR" 4
  121. .IX Item "-inkey filename|uri"
  122. The input key, by default it should be an RSA private key.
  123. .IP "\fB\-keyform\fR \fBDER\fR|\fBPEM\fR|\fBP12\fR|\fBENGINE\fR" 4
  124. .IX Item "-keyform DER|PEM|P12|ENGINE"
  125. The key format; unspecified by default.
  126. See \fBopenssl\-format\-options\fR\|(1) for details.
  127. .IP \fB\-pubin\fR 4
  128. .IX Item "-pubin"
  129. By default a private key is read from the key input.
  130. With this option a public key is read instead.
  131. If the input contains no public key but a private key, its public part is used.
  132. .IP \fB\-certin\fR 4
  133. .IX Item "-certin"
  134. The input is a certificate containing an RSA public key.
  135. .IP \fB\-sign\fR 4
  136. .IX Item "-sign"
  137. Sign the input data and output the signed result. This requires
  138. an RSA private key.
  139. .IP \fB\-verify\fR 4
  140. .IX Item "-verify"
  141. Verify the input data and output the recovered data.
  142. .IP \fB\-encrypt\fR 4
  143. .IX Item "-encrypt"
  144. Encrypt the input data using an RSA public key.
  145. .IP \fB\-decrypt\fR 4
  146. .IX Item "-decrypt"
  147. Decrypt the input data using an RSA private key.
  148. .IP "\fB\-pkcs\fR, \fB\-oaep\fR, \fB\-x931\fR, \fB\-raw\fR" 4
  149. .IX Item "-pkcs, -oaep, -x931, -raw"
  150. The padding to use: PKCS#1 v1.5 (the default), PKCS#1 OAEP,
  151. ANSI X9.31, or no padding, respectively.
  152. For signatures, only \fB\-pkcs\fR and \fB\-raw\fR can be used.
  153. .Sp
  154. Note: because of protection against Bleichenbacher attacks, decryption
  155. using PKCS#1 v1.5 mode will not return errors in case padding check failed.
  156. Use \fB\-raw\fR and inspect the returned value manually to check if the
  157. padding is correct.
  158. .IP \fB\-hexdump\fR 4
  159. .IX Item "-hexdump"
  160. Hex dump the output data.
  161. .IP \fB\-asn1parse\fR 4
  162. .IX Item "-asn1parse"
  163. Parse the ASN.1 output data, this is useful when combined with the
  164. \&\fB\-verify\fR option.
  165. .IP "\fB\-engine\fR \fIid\fR" 4
  166. .IX Item "-engine id"
  167. See "Engine Options" in \fBopenssl\fR\|(1).
  168. This option is deprecated.
  169. .IP "\fB\-rand\fR \fIfiles\fR, \fB\-writerand\fR \fIfile\fR" 4
  170. .IX Item "-rand files, -writerand file"
  171. See "Random State Options" in \fBopenssl\fR\|(1) for details.
  172. .IP "\fB\-provider\fR \fIname\fR" 4
  173. .IX Item "-provider name"
  174. .PD 0
  175. .IP "\fB\-provider\-path\fR \fIpath\fR" 4
  176. .IX Item "-provider-path path"
  177. .IP "\fB\-propquery\fR \fIpropq\fR" 4
  178. .IX Item "-propquery propq"
  179. .PD
  180. See "Provider Options" in \fBopenssl\fR\|(1), \fBprovider\fR\|(7), and \fBproperty\fR\|(7).
  181. .SH NOTES
  182. .IX Header "NOTES"
  183. Since this command uses the RSA algorithm directly, it can only be
  184. used to sign or verify small pieces of data.
  185. .SH EXAMPLES
  186. .IX Header "EXAMPLES"
  187. Examples equivalent to these can be found in the documentation for the
  188. non-deprecated \fBopenssl\-pkeyutl\fR\|(1) command.
  189. .PP
  190. Sign some data using a private key:
  191. .PP
  192. .Vb 1
  193. \& openssl rsautl \-sign \-in file \-inkey key.pem \-out sig
  194. .Ve
  195. .PP
  196. Recover the signed data
  197. .PP
  198. .Vb 1
  199. \& openssl rsautl \-verify \-in sig \-inkey key.pem
  200. .Ve
  201. .PP
  202. Examine the raw signed data:
  203. .PP
  204. .Vb 1
  205. \& openssl rsautl \-verify \-in sig \-inkey key.pem \-raw \-hexdump
  206. \&
  207. \& 0000 \- 00 01 ff ff ff ff ff ff\-ff ff ff ff ff ff ff ff ................
  208. \& 0010 \- ff ff ff ff ff ff ff ff\-ff ff ff ff ff ff ff ff ................
  209. \& 0020 \- ff ff ff ff ff ff ff ff\-ff ff ff ff ff ff ff ff ................
  210. \& 0030 \- ff ff ff ff ff ff ff ff\-ff ff ff ff ff ff ff ff ................
  211. \& 0040 \- ff ff ff ff ff ff ff ff\-ff ff ff ff ff ff ff ff ................
  212. \& 0050 \- ff ff ff ff ff ff ff ff\-ff ff ff ff ff ff ff ff ................
  213. \& 0060 \- ff ff ff ff ff ff ff ff\-ff ff ff ff ff ff ff ff ................
  214. \& 0070 \- ff ff ff ff 00 68 65 6c\-6c 6f 20 77 6f 72 6c 64 .....hello world
  215. .Ve
  216. .PP
  217. The PKCS#1 block formatting is evident from this. If this was done using
  218. encrypt and decrypt the block would have been of type 2 (the second byte)
  219. and random padding data visible instead of the 0xff bytes.
  220. .PP
  221. It is possible to analyse the signature of certificates using this
  222. command in conjunction with \fBopenssl\-asn1parse\fR\|(1). Consider the self signed
  223. example in \fIcerts/pca\-cert.pem\fR. Running \fBopenssl\-asn1parse\fR\|(1) as follows
  224. yields:
  225. .PP
  226. .Vb 1
  227. \& openssl asn1parse \-in pca\-cert.pem
  228. \&
  229. \& 0:d=0 hl=4 l= 742 cons: SEQUENCE
  230. \& 4:d=1 hl=4 l= 591 cons: SEQUENCE
  231. \& 8:d=2 hl=2 l= 3 cons: cont [ 0 ]
  232. \& 10:d=3 hl=2 l= 1 prim: INTEGER :02
  233. \& 13:d=2 hl=2 l= 1 prim: INTEGER :00
  234. \& 16:d=2 hl=2 l= 13 cons: SEQUENCE
  235. \& 18:d=3 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
  236. \& 29:d=3 hl=2 l= 0 prim: NULL
  237. \& 31:d=2 hl=2 l= 92 cons: SEQUENCE
  238. \& 33:d=3 hl=2 l= 11 cons: SET
  239. \& 35:d=4 hl=2 l= 9 cons: SEQUENCE
  240. \& 37:d=5 hl=2 l= 3 prim: OBJECT :countryName
  241. \& 42:d=5 hl=2 l= 2 prim: PRINTABLESTRING :AU
  242. \& ....
  243. \& 599:d=1 hl=2 l= 13 cons: SEQUENCE
  244. \& 601:d=2 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
  245. \& 612:d=2 hl=2 l= 0 prim: NULL
  246. \& 614:d=1 hl=3 l= 129 prim: BIT STRING
  247. .Ve
  248. .PP
  249. The final BIT STRING contains the actual signature. It can be extracted with:
  250. .PP
  251. .Vb 1
  252. \& openssl asn1parse \-in pca\-cert.pem \-out sig \-noout \-strparse 614
  253. .Ve
  254. .PP
  255. The certificate public key can be extracted with:
  256. .PP
  257. .Vb 1
  258. \& openssl x509 \-in test/testx509.pem \-pubkey \-noout >pubkey.pem
  259. .Ve
  260. .PP
  261. The signature can be analysed with:
  262. .PP
  263. .Vb 1
  264. \& openssl rsautl \-in sig \-verify \-asn1parse \-inkey pubkey.pem \-pubin
  265. \&
  266. \& 0:d=0 hl=2 l= 32 cons: SEQUENCE
  267. \& 2:d=1 hl=2 l= 12 cons: SEQUENCE
  268. \& 4:d=2 hl=2 l= 8 prim: OBJECT :md5
  269. \& 14:d=2 hl=2 l= 0 prim: NULL
  270. \& 16:d=1 hl=2 l= 16 prim: OCTET STRING
  271. \& 0000 \- f3 46 9e aa 1a 4a 73 c9\-37 ea 93 00 48 25 08 b5 .F...Js.7...H%..
  272. .Ve
  273. .PP
  274. This is the parsed version of an ASN1 DigestInfo structure. It can be seen that
  275. the digest used was md5. The actual part of the certificate that was signed can
  276. be extracted with:
  277. .PP
  278. .Vb 1
  279. \& openssl asn1parse \-in pca\-cert.pem \-out tbs \-noout \-strparse 4
  280. .Ve
  281. .PP
  282. and its digest computed with:
  283. .PP
  284. .Vb 2
  285. \& openssl md5 \-c tbs
  286. \& MD5(tbs)= f3:46:9e:aa:1a:4a:73:c9:37:ea:93:00:48:25:08:b5
  287. .Ve
  288. .PP
  289. which it can be seen agrees with the recovered value above.
  290. .SH "SEE ALSO"
  291. .IX Header "SEE ALSO"
  292. \&\fBopenssl\fR\|(1),
  293. \&\fBopenssl\-pkeyutl\fR\|(1),
  294. \&\fBopenssl\-dgst\fR\|(1),
  295. \&\fBopenssl\-rsa\fR\|(1),
  296. \&\fBopenssl\-genrsa\fR\|(1)
  297. .SH HISTORY
  298. .IX Header "HISTORY"
  299. This command was deprecated in OpenSSL 3.0.
  300. .PP
  301. The \fB\-engine\fR option was deprecated in OpenSSL 3.0.
  302. .SH COPYRIGHT
  303. .IX Header "COPYRIGHT"
  304. Copyright 2000\-2023 The OpenSSL Project Authors. All Rights Reserved.
  305. .PP
  306. Licensed under the Apache License 2.0 (the "License"). You may not use
  307. this file except in compliance with the License. You can obtain a copy
  308. in the file LICENSE in the source distribution or at
  309. <https://www.openssl.org/source/license.html>.