xref: /freebsd/crypto/openssl/doc/man1/openssl-rsautl.pod.in (revision aa7957345732816fb0ba8308798d2f79f45597f9)
1b077aed3SPierre Pronchery=pod
2b077aed3SPierre Pronchery{- OpenSSL::safe::output_do_not_edit_headers(); -}
3b077aed3SPierre Pronchery
4b077aed3SPierre Pronchery=head1 NAME
5b077aed3SPierre Pronchery
6b077aed3SPierre Proncheryopenssl-rsautl - RSA command
7b077aed3SPierre Pronchery
8b077aed3SPierre Pronchery=head1 SYNOPSIS
9b077aed3SPierre Pronchery
10b077aed3SPierre ProncheryB<openssl> B<rsautl>
11b077aed3SPierre Pronchery[B<-help>]
12b077aed3SPierre Pronchery[B<-in> I<file>]
13b077aed3SPierre Pronchery[B<-passin> I<arg>]
14b077aed3SPierre Pronchery[B<-rev>]
15b077aed3SPierre Pronchery[B<-out> I<file>]
16b077aed3SPierre Pronchery[B<-inkey> I<filename>|I<uri>]
17b077aed3SPierre Pronchery[B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE>]
18b077aed3SPierre Pronchery[B<-pubin>]
19b077aed3SPierre Pronchery[B<-certin>]
20b077aed3SPierre Pronchery[B<-sign>]
21b077aed3SPierre Pronchery[B<-verify>]
22b077aed3SPierre Pronchery[B<-encrypt>]
23b077aed3SPierre Pronchery[B<-decrypt>]
24b077aed3SPierre Pronchery[B<-pkcs>]
25b077aed3SPierre Pronchery[B<-x931>]
26b077aed3SPierre Pronchery[B<-oaep>]
27b077aed3SPierre Pronchery[B<-raw>]
28b077aed3SPierre Pronchery[B<-hexdump>]
29b077aed3SPierre Pronchery[B<-asn1parse>]
30b077aed3SPierre Pronchery{- $OpenSSL::safe::opt_engine_synopsis -}{- $OpenSSL::safe::opt_r_synopsis -}
31b077aed3SPierre Pronchery{- $OpenSSL::safe::opt_provider_synopsis -}
32b077aed3SPierre Pronchery
33b077aed3SPierre Pronchery=head1 DESCRIPTION
34b077aed3SPierre Pronchery
35b077aed3SPierre ProncheryThis command has been deprecated.
36b077aed3SPierre ProncheryThe L<openssl-pkeyutl(1)> command should be used instead.
37b077aed3SPierre Pronchery
38b077aed3SPierre ProncheryThis command can be used to sign, verify, encrypt and decrypt
39b077aed3SPierre Proncherydata using the RSA algorithm.
40b077aed3SPierre Pronchery
41b077aed3SPierre Pronchery=head1 OPTIONS
42b077aed3SPierre Pronchery
43b077aed3SPierre Pronchery=over 4
44b077aed3SPierre Pronchery
45b077aed3SPierre Pronchery=item B<-help>
46b077aed3SPierre Pronchery
47b077aed3SPierre ProncheryPrint out a usage message.
48b077aed3SPierre Pronchery
49b077aed3SPierre Pronchery=item B<-in> I<filename>
50b077aed3SPierre Pronchery
51b077aed3SPierre ProncheryThis specifies the input filename to read data from or standard input
52b077aed3SPierre Proncheryif this option is not specified.
53b077aed3SPierre Pronchery
54b077aed3SPierre Pronchery=item B<-passin> I<arg>
55b077aed3SPierre Pronchery
56b077aed3SPierre ProncheryThe passphrase used in the output file.
57b077aed3SPierre ProncherySee see L<openssl-passphrase-options(1)>.
58b077aed3SPierre Pronchery
59b077aed3SPierre Pronchery=item B<-rev>
60b077aed3SPierre Pronchery
61b077aed3SPierre ProncheryReverse the order of the input.
62b077aed3SPierre Pronchery
63b077aed3SPierre Pronchery=item B<-out> I<filename>
64b077aed3SPierre Pronchery
65b077aed3SPierre ProncherySpecifies the output filename to write to or standard output by
66b077aed3SPierre Proncherydefault.
67b077aed3SPierre Pronchery
68b077aed3SPierre Pronchery=item B<-inkey> I<filename>|I<uri>
69b077aed3SPierre Pronchery
70b077aed3SPierre ProncheryThe input key, by default it should be an RSA private key.
71b077aed3SPierre Pronchery
72b077aed3SPierre Pronchery=item B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE>
73b077aed3SPierre Pronchery
74b077aed3SPierre ProncheryThe key format; unspecified by default.
75b077aed3SPierre ProncherySee L<openssl-format-options(1)> for details.
76b077aed3SPierre Pronchery
77b077aed3SPierre Pronchery=item B<-pubin>
78b077aed3SPierre Pronchery
79b077aed3SPierre ProncheryThe input file is an RSA public key.
80b077aed3SPierre Pronchery
81b077aed3SPierre Pronchery=item B<-certin>
82b077aed3SPierre Pronchery
83b077aed3SPierre ProncheryThe input is a certificate containing an RSA public key.
84b077aed3SPierre Pronchery
85b077aed3SPierre Pronchery=item B<-sign>
86b077aed3SPierre Pronchery
87b077aed3SPierre ProncherySign the input data and output the signed result. This requires
88b077aed3SPierre Proncheryan RSA private key.
89b077aed3SPierre Pronchery
90b077aed3SPierre Pronchery=item B<-verify>
91b077aed3SPierre Pronchery
92b077aed3SPierre ProncheryVerify the input data and output the recovered data.
93b077aed3SPierre Pronchery
94b077aed3SPierre Pronchery=item B<-encrypt>
95b077aed3SPierre Pronchery
96b077aed3SPierre ProncheryEncrypt the input data using an RSA public key.
97b077aed3SPierre Pronchery
98b077aed3SPierre Pronchery=item B<-decrypt>
99b077aed3SPierre Pronchery
100b077aed3SPierre ProncheryDecrypt the input data using an RSA private key.
101b077aed3SPierre Pronchery
102*aa795734SPierre Pronchery=item B<-pkcs>, B<-oaep>, B<-x931>, B<-raw>
103b077aed3SPierre Pronchery
104b077aed3SPierre ProncheryThe padding to use: PKCS#1 v1.5 (the default), PKCS#1 OAEP,
105b077aed3SPierre ProncheryANSI X9.31, or no padding, respectively.
106b077aed3SPierre ProncheryFor signatures, only B<-pkcs> and B<-raw> can be used.
107b077aed3SPierre Pronchery
108b077aed3SPierre Pronchery=item B<-hexdump>
109b077aed3SPierre Pronchery
110b077aed3SPierre ProncheryHex dump the output data.
111b077aed3SPierre Pronchery
112b077aed3SPierre Pronchery=item B<-asn1parse>
113b077aed3SPierre Pronchery
114b077aed3SPierre ProncheryParse the ASN.1 output data, this is useful when combined with the
115b077aed3SPierre ProncheryB<-verify> option.
116b077aed3SPierre Pronchery
117b077aed3SPierre Pronchery{- $OpenSSL::safe::opt_engine_item -}
118b077aed3SPierre Pronchery
119b077aed3SPierre Pronchery{- $OpenSSL::safe::opt_r_item -}
120b077aed3SPierre Pronchery
121b077aed3SPierre Pronchery{- $OpenSSL::safe::opt_provider_item -}
122b077aed3SPierre Pronchery
123b077aed3SPierre Pronchery=back
124b077aed3SPierre Pronchery
125b077aed3SPierre Pronchery=head1 NOTES
126b077aed3SPierre Pronchery
127b077aed3SPierre ProncherySince this command uses the RSA algorithm directly, it can only be
128b077aed3SPierre Proncheryused to sign or verify small pieces of data.
129b077aed3SPierre Pronchery
130b077aed3SPierre Pronchery=head1 EXAMPLES
131b077aed3SPierre Pronchery
132b077aed3SPierre ProncheryExamples equivalent to these can be found in the documentation for the
133b077aed3SPierre Proncherynon-deprecated L<openssl-pkeyutl(1)> command.
134b077aed3SPierre Pronchery
135b077aed3SPierre ProncherySign some data using a private key:
136b077aed3SPierre Pronchery
137b077aed3SPierre Pronchery openssl rsautl -sign -in file -inkey key.pem -out sig
138b077aed3SPierre Pronchery
139b077aed3SPierre ProncheryRecover the signed data
140b077aed3SPierre Pronchery
141b077aed3SPierre Pronchery openssl rsautl -verify -in sig -inkey key.pem
142b077aed3SPierre Pronchery
143b077aed3SPierre ProncheryExamine the raw signed data:
144b077aed3SPierre Pronchery
145b077aed3SPierre Pronchery openssl rsautl -verify -in sig -inkey key.pem -raw -hexdump
146b077aed3SPierre Pronchery
147b077aed3SPierre Pronchery 0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
148b077aed3SPierre Pronchery 0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
149b077aed3SPierre Pronchery 0020 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
150b077aed3SPierre Pronchery 0030 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
151b077aed3SPierre Pronchery 0040 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
152b077aed3SPierre Pronchery 0050 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
153b077aed3SPierre Pronchery 0060 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff   ................
154b077aed3SPierre Pronchery 0070 - ff ff ff ff 00 68 65 6c-6c 6f 20 77 6f 72 6c 64   .....hello world
155b077aed3SPierre Pronchery
156b077aed3SPierre ProncheryThe PKCS#1 block formatting is evident from this. If this was done using
157b077aed3SPierre Proncheryencrypt and decrypt the block would have been of type 2 (the second byte)
158b077aed3SPierre Proncheryand random padding data visible instead of the 0xff bytes.
159b077aed3SPierre Pronchery
160b077aed3SPierre ProncheryIt is possible to analyse the signature of certificates using this
161b077aed3SPierre Proncherycommand in conjunction with L<openssl-asn1parse(1)>. Consider the self signed
162b077aed3SPierre Proncheryexample in F<certs/pca-cert.pem>. Running L<openssl-asn1parse(1)> as follows
163b077aed3SPierre Proncheryyields:
164b077aed3SPierre Pronchery
165b077aed3SPierre Pronchery openssl asn1parse -in pca-cert.pem
166b077aed3SPierre Pronchery
167b077aed3SPierre Pronchery    0:d=0  hl=4 l= 742 cons: SEQUENCE
168b077aed3SPierre Pronchery    4:d=1  hl=4 l= 591 cons:  SEQUENCE
169b077aed3SPierre Pronchery    8:d=2  hl=2 l=   3 cons:   cont [ 0 ]
170b077aed3SPierre Pronchery   10:d=3  hl=2 l=   1 prim:    INTEGER           :02
171b077aed3SPierre Pronchery   13:d=2  hl=2 l=   1 prim:   INTEGER           :00
172b077aed3SPierre Pronchery   16:d=2  hl=2 l=  13 cons:   SEQUENCE
173b077aed3SPierre Pronchery   18:d=3  hl=2 l=   9 prim:    OBJECT            :md5WithRSAEncryption
174b077aed3SPierre Pronchery   29:d=3  hl=2 l=   0 prim:    NULL
175b077aed3SPierre Pronchery   31:d=2  hl=2 l=  92 cons:   SEQUENCE
176b077aed3SPierre Pronchery   33:d=3  hl=2 l=  11 cons:    SET
177b077aed3SPierre Pronchery   35:d=4  hl=2 l=   9 cons:     SEQUENCE
178b077aed3SPierre Pronchery   37:d=5  hl=2 l=   3 prim:      OBJECT            :countryName
179b077aed3SPierre Pronchery   42:d=5  hl=2 l=   2 prim:      PRINTABLESTRING   :AU
180b077aed3SPierre Pronchery  ....
181b077aed3SPierre Pronchery  599:d=1  hl=2 l=  13 cons:  SEQUENCE
182b077aed3SPierre Pronchery  601:d=2  hl=2 l=   9 prim:   OBJECT            :md5WithRSAEncryption
183b077aed3SPierre Pronchery  612:d=2  hl=2 l=   0 prim:   NULL
184b077aed3SPierre Pronchery  614:d=1  hl=3 l= 129 prim:  BIT STRING
185b077aed3SPierre Pronchery
186b077aed3SPierre Pronchery
187b077aed3SPierre ProncheryThe final BIT STRING contains the actual signature. It can be extracted with:
188b077aed3SPierre Pronchery
189b077aed3SPierre Pronchery openssl asn1parse -in pca-cert.pem -out sig -noout -strparse 614
190b077aed3SPierre Pronchery
191b077aed3SPierre ProncheryThe certificate public key can be extracted with:
192b077aed3SPierre Pronchery
193b077aed3SPierre Pronchery openssl x509 -in test/testx509.pem -pubkey -noout >pubkey.pem
194b077aed3SPierre Pronchery
195b077aed3SPierre ProncheryThe signature can be analysed with:
196b077aed3SPierre Pronchery
197b077aed3SPierre Pronchery openssl rsautl -in sig -verify -asn1parse -inkey pubkey.pem -pubin
198b077aed3SPierre Pronchery
199b077aed3SPierre Pronchery    0:d=0  hl=2 l=  32 cons: SEQUENCE
200b077aed3SPierre Pronchery    2:d=1  hl=2 l=  12 cons:  SEQUENCE
201b077aed3SPierre Pronchery    4:d=2  hl=2 l=   8 prim:   OBJECT            :md5
202b077aed3SPierre Pronchery   14:d=2  hl=2 l=   0 prim:   NULL
203b077aed3SPierre Pronchery   16:d=1  hl=2 l=  16 prim:  OCTET STRING
204b077aed3SPierre Pronchery      0000 - f3 46 9e aa 1a 4a 73 c9-37 ea 93 00 48 25 08 b5   .F...Js.7...H%..
205b077aed3SPierre Pronchery
206b077aed3SPierre ProncheryThis is the parsed version of an ASN1 DigestInfo structure. It can be seen that
207b077aed3SPierre Proncherythe digest used was md5. The actual part of the certificate that was signed can
208b077aed3SPierre Proncherybe extracted with:
209b077aed3SPierre Pronchery
210b077aed3SPierre Pronchery openssl asn1parse -in pca-cert.pem -out tbs -noout -strparse 4
211b077aed3SPierre Pronchery
212b077aed3SPierre Proncheryand its digest computed with:
213b077aed3SPierre Pronchery
214b077aed3SPierre Pronchery openssl md5 -c tbs
215b077aed3SPierre Pronchery MD5(tbs)= f3:46:9e:aa:1a:4a:73:c9:37:ea:93:00:48:25:08:b5
216b077aed3SPierre Pronchery
217b077aed3SPierre Proncherywhich it can be seen agrees with the recovered value above.
218b077aed3SPierre Pronchery
219b077aed3SPierre Pronchery=head1 SEE ALSO
220b077aed3SPierre Pronchery
221b077aed3SPierre ProncheryL<openssl(1)>,
222b077aed3SPierre ProncheryL<openssl-pkeyutl(1)>,
223b077aed3SPierre ProncheryL<openssl-dgst(1)>,
224b077aed3SPierre ProncheryL<openssl-rsa(1)>,
225b077aed3SPierre ProncheryL<openssl-genrsa(1)>
226b077aed3SPierre Pronchery
227b077aed3SPierre Pronchery=head1 HISTORY
228b077aed3SPierre Pronchery
229b077aed3SPierre ProncheryThis command was deprecated in OpenSSL 3.0.
230b077aed3SPierre Pronchery
231b077aed3SPierre ProncheryThe B<-engine> option was deprecated in OpenSSL 3.0.
232b077aed3SPierre Pronchery
233b077aed3SPierre Pronchery=head1 COPYRIGHT
234b077aed3SPierre Pronchery
235*aa795734SPierre ProncheryCopyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.
236b077aed3SPierre Pronchery
237b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
238b077aed3SPierre Proncherythis file except in compliance with the License.  You can obtain a copy
239b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at
240b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>.
241b077aed3SPierre Pronchery
242b077aed3SPierre Pronchery=cut
243