1=pod 2{- OpenSSL::safe::output_do_not_edit_headers(); -} 3 4=head1 NAME 5 6openssl-pkeyutl - asymmetric key command 7 8=head1 SYNOPSIS 9 10B<openssl> B<pkeyutl> 11[B<-help>] 12[B<-in> I<file>] 13[B<-rawin>] 14[B<-digest> I<algorithm>] 15[B<-out> I<file>] 16[B<-secret> I<file>] 17[B<-sigfile> I<file>] 18[B<-inkey> I<filename>|I<uri>] 19[B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE>] 20[B<-passin> I<arg>] 21[B<-pubin>] 22[B<-certin>] 23[B<-rev>] 24[B<-sign>] 25[B<-verify>] 26[B<-verifyrecover>] 27[B<-encrypt>] 28[B<-decrypt>] 29[B<-derive>] 30[B<-peerkey> I<file>] 31[B<-peerform> B<DER>|B<PEM>|B<P12>|B<ENGINE>] 32[B<-encap>] 33[B<-decap>] 34[B<-kdf> I<algorithm>] 35[B<-kdflen> I<length>] 36[B<-kemop> I<mode>] 37[B<-pkeyopt> I<opt>:I<value>] 38[B<-pkeyopt_passin> I<opt>[:I<passarg>]] 39[B<-hexdump>] 40[B<-asn1parse>] 41{- $OpenSSL::safe::opt_engine_synopsis -}[B<-engine_impl>] 42{- $OpenSSL::safe::opt_r_synopsis -} 43{- $OpenSSL::safe::opt_provider_synopsis -} 44{- $OpenSSL::safe::opt_config_synopsis -} 45 46=head1 DESCRIPTION 47 48This command can be used to perform low-level operations 49on asymmetric (public or private) keys using any supported algorithm. 50 51By default the signing operation (see B<-sign> option) is assumed. 52 53=head1 OPTIONS 54 55=over 4 56 57=item B<-help> 58 59Print out a usage message. 60 61=item B<-in> I<filename> 62 63This specifies the input filename to read data from or standard input 64if this option is not specified. 65 66=item B<-rawin> 67 68This indicates that the signature or verification input data is raw data, 69which is not hashed by any message digest algorithm. 70Except with EdDSA, 71the user can specify a digest algorithm by using the B<-digest> option. 72For signature algorithms like RSA, DSA and ECDSA, 73the default digest algorithm is SHA256. For SM2, it is SM3. 74 75This option can only be used with B<-sign> and B<-verify>. 76For EdDSA (the Ed25519 and Ed448 algorithms) this option 77is implied since OpenSSL 3.5, and required in earlier versions. 78 79The B<-digest> option implies B<-rawin> since OpenSSL 3.5. 80 81=item B<-digest> I<algorithm> 82 83This option can only be used with B<-sign> and B<-verify>. 84It specifies the digest algorithm that is used to hash the input data 85before signing or verifying it with the input key. This option could be omitted 86if the signature algorithm does not require preprocessing the input through 87a pluggable hash function before signing (for instance, EdDSA). If this option 88is omitted but the signature algorithm requires one and the B<-rawin> option 89is given, a default value will be used (see B<-rawin> for details). 90If this option is present, then the B<-rawin> option 91is implied since OpenSSL 3.5, and required in earlier versions. 92 93At this time, HashEdDSA (the ph or "prehash" variant of EdDSA) is not supported, 94so the B<-digest> option cannot be used with EdDSA. 95 96=item B<-out> I<filename> 97 98Specifies the output filename to write to or standard output by default. 99 100=item B<-secret> I<filename> 101 102Specifies the shared-secret output filename for when performing encapsulation 103via the B<-encap> option or decapsulation via the B<-decap> option. 104The B<-encap> option also produces a separate (public) ciphertext output which 105is by default written to standard output, but being I<binary> non-text data, 106is typically also redirected to a file selected via the I<-out> option. 107 108=item B<-sigfile> I<file> 109 110Signature file, required and allowed for B<-verify> operations only. 111 112=item B<-inkey> I<filename>|I<uri> 113 114The input key, by default it should be a private key. 115 116=item B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE> 117 118The key format; unspecified by default. 119See L<openssl-format-options(1)> for details. 120 121=item B<-passin> I<arg> 122 123The input key password source. For more information about the format of I<arg> 124see L<openssl-passphrase-options(1)>. 125 126=item B<-pubin> 127 128By default a private key is read from the key input. 129With this option a public key is read instead. 130If the input contains no public key but a private key, its public part is used. 131 132=item B<-certin> 133 134The input is a certificate containing a public key. 135 136=item B<-rev> 137 138Reverse the order of the input buffer. This is useful for some libraries 139(such as CryptoAPI) which represent the buffer in little-endian format. 140This cannot be used in conjunction with B<-rawin>. 141 142=item B<-sign> 143 144Sign the input data and output the signed result. This requires a private key. 145Using a message digest operation along with this is recommended, 146when applicable, see the B<-rawin> and B<-digest> options for details. 147Otherwise, the input data given with the B<-in> option is assumed to already 148be a digest, but this may then require an additional B<-pkeyopt> C<digest:>I<md> 149in some cases (e.g., RSA with the default PKCS#1 padding mode). 150Even for other algorithms like ECDSA, where the additional B<-pkeyopt> option 151does not affect signature output, it is recommended, as it enables 152checking that the input length is consistent with the intended digest. 153 154=item B<-verify> 155 156Verify the input data against the signature given with the B<-sigfile> option 157and indicate if the verification succeeded or failed. 158The input data given with the B<-in> option is assumed to be a hash value 159unless the B<-rawin> option is specified or implied. 160With raw data, when a digest algorithm is applicable, though it may be inferred 161from the signature or take a default value, it should also be specified. 162 163=item B<-verifyrecover> 164 165Verify the given signature and output the recovered data (signature payload). 166For example, in case of RSA PKCS#1 the recovered data is the B<EMSA-PKCS-v1_5> 167DER encoding of the digest algorithm OID and value as specified in 168L<RFC8017 Section 9.2|https://datatracker.ietf.org/doc/html/rfc8017#section-9.2>. 169 170Note that here the input given with the B<-in> option is not a signature input 171(as with the B<-sign> and B<-verify> options) but a signature output value, 172typically produced using the B<-sign> option. 173 174This option is available only for use with RSA keys. 175 176=item B<-encrypt> 177 178Encrypt the input data using a public key. 179 180=item B<-decrypt> 181 182Decrypt the input data using a private key. 183 184=item B<-derive> 185 186Derive a shared secret using own private (EC)DH key and peer key. 187 188=item B<-peerkey> I<file> 189 190File containing the peer public or private (EC)DH key 191to use with the key derivation (agreement) operation. 192Its type must match the type of the own private key given with B<-inkey>. 193 194=item B<-peerform> B<DER>|B<PEM>|B<P12>|B<ENGINE> 195 196The peer key format; unspecified by default. 197See L<openssl-format-options(1)> for details. 198 199=item B<-encap> 200 201Use a Key Encapsulation Mechanism (B<KEM>) to B<encapsulate> a shared-secret to 202a peer's B<public> key. 203The encapsulated result (or ciphertext, non-text binary data) is written to 204standard output by default, or else to the file specified with I<-out>. 205The I<-secret> option must also be provided to specify the output file for the 206derived shared-secret value generated in the encapsulation process. 207Encapsulation is supported with a number of public key algorithms, currently: 208L<ML-KEM|EVP_PKEY-ML-KEM(7)>, 209L<X25519|EVP_KEM-X25519(7)>, 210L<X449|EVP_KEM-X448(7)>, 211and 212L<EC|EVP_KEM-EC(7)>. 213The ECX and EC algorithms use the 214L<RFC9180|https://www.rfc-editor.org/rfc/rfc9180> DHKEM construction. 215Encapsulation is also supported with L<RSA|EVP_KEM-RSA(7)> keys via the 216B<RSASVE> construction. 217 218At the API level, encapsulation and decapsulation are also supported for a few 219hybrid ECDHE (no DHKEM) plus B<ML-KEM> algorithms, but these are intended 220primarily for use with TLS and should not be used standalone. 221There are in any case no standard public and private key formats for the hybrid 222algorithms, so it is not possible to provide the required key material. 223 224=item B<-decap> 225 226Decode an encapsulated secret, with the use of a B<-private> key, to derive the 227same shared-secret as that obtained when the secret was encapsulated to the 228corresponding public key. 229The encapsulated secret is by default read from the standard input, or else 230from the file specified with B<-in>. 231The derived shared-secret is written to the file specified with the B<-secret> 232option, which I<must> also be provided. 233Decapsulation is supported with a number of public key algorithms, currently: 234L<ML-KEM|EVP_PKEY-ML-KEM(7)>, 235L<X25519|EVP_KEM-X25519(7)>, 236L<X448|EVP_KEM-X448(7)>, 237and 238L<EC|EVP_KEM-EC(7)>. 239The ECX and EC algorithms use the 240L<RFC9180|https://www.rfc-editor.org/rfc/rfc9180> DHKEM construction. 241Decapsulation is also supported with L<RSA|EVP_KEM-RSA(7)> keys via the 242B<RSASVE> construction. 243 244=item B<-kemop> I<mode> 245 246This option is used with the I<-encap>/I<-decap> commands and specifies the KEM 247I<mode> specific for the key algorithm when there is no default way to 248encapsulate and decapsulate shared secrets with the chosen key type. 249All the supported algorithms presently support only their default I<mode>, and 250this option, though available, is not required. 251 252=item B<-kdf> I<algorithm> 253 254Use key derivation function I<algorithm>. The supported algorithms are 255at present B<TLS1-PRF> and B<HKDF>. 256Note: additional parameters and the KDF output length will normally have to be 257set for this to work. 258See L<EVP_PKEY_CTX_set_hkdf_md(3)> and L<EVP_PKEY_CTX_set_tls1_prf_md(3)> 259for the supported string parameters of each algorithm. 260 261=item B<-kdflen> I<length> 262 263Set the output length for KDF. 264 265=item B<-pkeyopt> I<opt>:I<value> 266 267Public key options specified as opt:value. See NOTES below for more details. 268 269=item B<-pkeyopt_passin> I<opt>[:I<passarg>] 270 271Allows reading a public key option I<opt> from stdin or a password source. 272If only I<opt> is specified, the user will be prompted to enter a password on 273stdin. Alternatively, I<passarg> can be specified which can be any value 274supported by L<openssl-passphrase-options(1)>. 275 276=item B<-hexdump> 277 278hex dump the output data. 279 280=item B<-asn1parse> 281 282Parse the ASN.1 output data to check its DER encoding and print any errors. 283When combined with the B<-verifyrecover> option, this may be useful in case 284an ASN.1 DER-encoded structure had been signed directly (without hashing it) 285and when checking a signature in PKCS#1 v1.5 format, which has a DER encoding. 286 287{- $OpenSSL::safe::opt_engine_item -} 288 289{- output_off() if $disabled{"deprecated-3.0"}; "" -} 290=item B<-engine_impl> 291 292When used with the B<-engine> option, it specifies to also use 293engine I<id> for crypto operations. 294{- output_on() if $disabled{"deprecated-3.0"}; "" -} 295 296{- $OpenSSL::safe::opt_r_item -} 297 298{- $OpenSSL::safe::opt_provider_item -} 299 300{- $OpenSSL::safe::opt_config_item -} 301 302=back 303 304=head1 NOTES 305 306The operations and options supported vary according to the key algorithm 307and its implementation. The OpenSSL operations and options are indicated below. 308 309Unless otherwise mentioned, the B<-pkeyopt> option supports 310for all public-key types the C<digest:>I<alg> argument, 311which specifies the digest in use for the signing and verification operations. 312The value I<alg> should represent a digest name as used in the 313EVP_get_digestbyname() function for example B<sha256>. This value is not used to 314hash the input data. It is used (by some algorithms) for sanity-checking the 315lengths of data passed in and for creating the structures that make up the 316signature (e.g., B<DigestInfo> in RSASSA PKCS#1 v1.5 signatures). 317 318For instance, 319if the value of the B<-pkeyopt> option C<digest> argument is B<sha256>, 320the signature or verification input should be the 32 bytes long binary value 321of the SHA256 hash function output. 322 323Unless B<-rawin> is used or implied, this command does not hash the input data 324but rather it will use the data directly as input to the signature algorithm. 325Depending on the key type, signature type, and mode of padding, the maximum 326sensible lengths of input data differ. With RSA the signed data cannot be longer 327than the key modulus. In case of ECDSA and DSA the data should not be longer 328than the field size, otherwise it will be silently truncated to the field size. 329In any event the input size must not be larger than the largest supported digest 330output size B<EVP_MAX_MD_SIZE>, which currently is 64 bytes. 331 332=head1 RSA ALGORITHM 333 334The RSA algorithm generally supports the encrypt, decrypt, sign, 335verify and verifyrecover operations. However, some padding modes 336support only a subset of these operations. The following additional 337B<pkeyopt> values are supported: 338 339=over 4 340 341=item B<rsa_padding_mode:>I<mode> 342 343This sets the RSA padding mode. Acceptable values for I<mode> are B<pkcs1> for 344PKCS#1 padding, B<none> for no padding, B<oaep> 345for B<OAEP> mode, B<x931> for X9.31 mode and B<pss> for PSS. 346 347In PKCS#1 padding, if the message digest is not set, then the supplied data is 348signed or verified directly instead of using a B<DigestInfo> structure. If a 349digest is set, then the B<DigestInfo> structure is used and its length 350must correspond to the digest type. 351 352Note, for B<pkcs1> padding, as a protection against the Bleichenbacher attack, 353the decryption will not fail in case of padding check failures. Use B<none> 354and manual inspection of the decrypted message to verify if the decrypted 355value has correct PKCS#1 v1.5 padding. 356 357For B<oaep> mode only encryption and decryption is supported. 358 359For B<x931> if the digest type is set it is used to format the block data 360otherwise the first byte is used to specify the X9.31 digest ID. Sign, 361verify and verifyrecover are can be performed in this mode. 362 363For B<pss> mode only sign and verify are supported and the digest type must be 364specified. 365 366=item B<rsa_pss_saltlen:>I<len> 367 368For B<pss> mode only this option specifies the salt length. Three special 369values are supported: B<digest> sets the salt length to the digest length, 370B<max> sets the salt length to the maximum permissible value. When verifying 371B<auto> causes the salt length to be automatically determined based on the 372B<PSS> block structure. 373 374=item B<rsa_mgf1_md:>I<digest> 375 376For PSS and OAEP padding sets the MGF1 digest. If the MGF1 digest is not 377explicitly set in PSS mode then the signing digest is used. 378 379=item B<rsa_oaep_md:>I<digest> 380 381Sets the digest used for the OAEP hash function. If not explicitly set then 382SHA256 is used. 383 384=item B<rsa_pkcs1_implicit_rejection:>I<flag> 385 386Disables (when set to 0) or enables (when set to 1) the use of implicit 387rejection with PKCS#1 v1.5 decryption. When enabled (the default), as a 388protection against Bleichenbacher attack, the library will generate a 389deterministic random plaintext that it will return to the caller in case 390of padding check failure. 391When disabled, it's the callers' responsibility to handle the returned 392errors in a side-channel free manner. 393 394=back 395 396=head1 RSA-PSS ALGORITHM 397 398The RSA-PSS algorithm is a restricted version of the RSA algorithm which only 399supports the sign and verify operations with PSS padding. The following 400additional B<-pkeyopt> values are supported: 401 402=over 4 403 404=item B<rsa_padding_mode:>I<mode>, B<rsa_pss_saltlen:>I<len>, 405B<rsa_mgf1_md:>I<digest> 406 407These have the same meaning as the B<RSA> algorithm with some additional 408restrictions. The padding mode can only be set to B<pss> which is the 409default value. 410 411If the key has parameter restrictions then the digest, MGF1 412digest and salt length are set to the values specified in the parameters. 413The digest and MG cannot be changed and the salt length cannot be set to a 414value less than the minimum restriction. 415 416=back 417 418=head1 DSA ALGORITHM 419 420The DSA algorithm supports signing and verification operations only. Currently 421there are no additional B<-pkeyopt> options other than B<digest>. The SHA256 422digest is assumed by default. 423 424=head1 DH ALGORITHM 425 426The DH algorithm only supports the derivation operation and no additional 427B<-pkeyopt> options. 428 429=head1 EC ALGORITHM 430 431The EC algorithm supports sign, verify and derive operations. The sign and 432verify operations use ECDSA and derive uses ECDH. SHA256 is assumed by default 433for the B<-pkeyopt> B<digest> option. 434 435=head1 X25519 AND X448 ALGORITHMS 436 437The X25519 and X448 algorithms support key derivation only. Currently there are 438no additional options. 439 440=head2 SLH-DSA ALGORITHMS 441 442The SLH-DSA algorithms (SLH-DSA-SHA2-128s, SLH-DSA-SHA2-128f, SLH-DSA-SHA2-192s, SLH-DSA-SHA2-192f, SLH-DSA-SHA2-256s, SLH-DSA-SHA2-256f) are post-quantum signature algorithms. When using SLH-DSA with pkeyutl, the following options are available: 443 444=over 4 445 446=item B<-sign> 447 448Sign the input data using an SLH-DSA private key. For example: 449 450 $ openssl pkeyutl -sign -in file.txt -inkey slhdsa.pem -out sig 451 452=item B<-verify> 453 454Verify the signature using an SLH-DSA public key. For example: 455 456 $ openssl pkeyutl -verify -in file.txt -inkey slhdsa.pem -sigfile sig 457 458=back 459 460See L<EVP_PKEY-SLH-DSA(7)> and L<EVP_SIGNATURE-SLH-DSA(7)> for additional details about the SLH-DSA algorithm and its implementation. 461 462=head1 ML-DSA-44, ML-DSA-65 AND ML-DSA-87 ALGORITHMS 463 464The ML-DSA algorithms are post-quantum signature algorithms that support signing and verification of "raw" messages. 465No preliminary hashing is performed. When using ML-DSA with pkeyutl, the following options are available: 466 467=over 4 468 469=item B<-sign> 470 471Sign the input data using an ML-DSA private key. For example: 472 473 $ openssl pkeyutl -sign -in file.txt -inkey mldsa65.pem -out sig 474 475=item B<-verify> 476 477Verify the signature using an ML-DSA public key. For example: 478 479 $ openssl pkeyutl -verify -in file.txt -inkey mldsa65.pem -sigfile sig 480 481=item B<-pkeyopt> I<opt>:I<value> 482 483Additional options for ML-DSA signing and verification: 484 485=over 4 486 487=item B<message-encoding>:I<value> 488 489Specifies the message encoding mode used for signing. This controls how the input message is processed before signing. Valid values are described in L<EVP_SIGNATURE-ML-DSA(7)>. For example: 490 491 $ openssl pkeyutl -sign -in file.txt -inkey mldsa65.pem -out sig -pkeyopt message-encoding:1 492 493=item B<test-entropy>:I<value> 494 495Specifies a test entropy value for deterministic signing. For example: 496 497 $ openssl pkeyutl -sign -in file.txt -inkey mldsa65.pem -out sig -pkeyopt test-entropy:abcdefghijklmnopqrstuvwxyz012345 498 499=item B<hextest-entropy>:I<value> 500 501Specifies a test entropy value in hex format. For example: 502 503 $ openssl pkeyutl -sign -in file.txt -inkey mldsa65.pem -out sig -pkeyopt hextest-entropy:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 504 505=item B<deterministic>:I<value> 506 507Enables deterministic signing. For example: 508 509 $ openssl pkeyutl -sign -in file.txt -inkey mldsa65.pem -out sig -pkeyopt deterministic:1 510 511=item B<mu>:I<value> 512 513Specifies the mu parameter. For example: 514 515 $ echo -n "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" >file.txt 516 $ openssl pkeyutl -sign -in file.txt -inkey mldsa65.pem -out sig -pkeyopt mu:1 517 518=back 519 520=item B<context-string>:I<string> 521 522Specifies a context string for both signing and verification operations. The context string must be the same for verification to succeed. For example: 523 524 $ openssl pkeyutl -sign -in file.txt -inkey mldsa65.pem -out sig -pkeyopt context-string:mycontext 525 $ openssl pkeyutl -verify -in file.txt -inkey mldsa65.pem -sigfile sig -pkeyopt context-string:mycontext 526 527=item B<hexcontext-string>:I<string> 528 529Specifies a context string in hex format, allowing binary control values. For example: 530 531 $ openssl pkeyutl -sign -in file.txt -inkey mldsa65.pem -out sig -pkeyopt hexcontext-string:6d79636f6e74657874 532 533=back 534 535The signing operation supports a B<deterministic>:I<bool> option, 536with I<bool> set to C<1> if a deterministic signature is to be generated 537with a fixed all zero random input. 538By default, or if the I<bool> is C<0> a random entropy value is used. 539A deterministic result can also be obtained by specifying an explicit 540entropy value via the B<hextest-entropy>:I<value> parameter. 541Deterministic B<ML-DSA> signing should only be used in tests. 542 543See L<EVP_SIGNATURE-ML-DSA(7)> for additional details about the ML-DSA algorithms and their implementation. 544 545=head1 ML-KEM-512, ML-KEM-768 AND ML-KEM-1024 ALGORITHMS 546 547The ML-KEM algorithms support encapsulation and decapsulation only. 548The encapsulation operation supports a B<hexikme>:I<entropy> option, 549with I<entropy> the 64 hexadecimal digit encoding of a 32-byte value. 550This should only be used in tests, known or leaked values of the option may 551compromise the generated shared secret. 552 553See L<EVP_KEM-ML-KEM(7)> for additional detail. 554 555=head1 ED25519 AND ED448 ALGORITHMS 556 557These algorithms only support signing and verifying. OpenSSL only implements the 558"pure" variants of these algorithms so raw data can be passed directly to them 559without hashing them first. OpenSSL only supports 560"oneshot" operation with these algorithms. This means that the entire file to 561be signed/verified must be read into memory before processing it. Signing or 562Verifying very large files should be avoided. Additionally the size of the file 563must be known for this to work. If the size of the file cannot be determined 564(for example if the input is stdin) then the sign or verify operation will fail. 565 566=head1 SM2 567 568The SM2 algorithm supports sign, verify, encrypt and decrypt operations. For 569the sign and verify operations, SM2 requires an Distinguishing ID string to 570be passed in. The following B<-pkeyopt> value is supported: 571 572=over 4 573 574=item B<distid:>I<string> 575 576This sets the ID string used in SM2 sign or verify operations. While verifying 577an SM2 signature, the ID string must be the same one used when signing the data. 578Otherwise the verification will fail. 579 580=item B<hexdistid:>I<hex_string> 581 582This sets the ID string used in SM2 sign or verify operations. While verifying 583an SM2 signature, the ID string must be the same one used when signing the data. 584Otherwise the verification will fail. The ID string provided with this option 585should be a valid hexadecimal value. 586 587=back 588 589=head1 EXAMPLES 590 591Sign some data using a private key: 592 593 openssl pkeyutl -sign -in file -inkey key.pem -out sig 594 595Recover the signed data (e.g. if an RSA key is used): 596 597 openssl pkeyutl -verifyrecover -in sig -inkey key.pem 598 599Verify the signature (e.g. a DSA key): 600 601 openssl pkeyutl -verify -in file -sigfile sig -inkey key.pem 602 603Sign data using a message digest value (this is currently only valid for RSA): 604 605 openssl pkeyutl -sign -in file -inkey key.pem -out sig -pkeyopt digest:sha256 606 607Derive a shared secret value: 608 609 openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret 610 611Hexdump 48 bytes of TLS1 PRF using digest B<SHA256> and shared secret and 612seed consisting of the single byte 0xFF: 613 614 openssl pkeyutl -kdf TLS1-PRF -kdflen 48 -pkeyopt md:SHA256 \ 615 -pkeyopt hexsecret:ff -pkeyopt hexseed:ff -hexdump 616 617Derive a key using B<scrypt> where the password is read from command line: 618 619 openssl pkeyutl -kdf scrypt -kdflen 16 -pkeyopt_passin pass \ 620 -pkeyopt hexsalt:aabbcc -pkeyopt N:16384 -pkeyopt r:8 -pkeyopt p:1 621 622Derive using the same algorithm, but read key from environment variable MYPASS: 623 624 openssl pkeyutl -kdf scrypt -kdflen 16 -pkeyopt_passin pass:env:MYPASS \ 625 -pkeyopt hexsalt:aabbcc -pkeyopt N:16384 -pkeyopt r:8 -pkeyopt p:1 626 627Sign some data using an L<SM2(7)> private key and a specific ID: 628 629 openssl pkeyutl -sign -in file -inkey sm2.key -out sig -rawin -digest sm3 \ 630 -pkeyopt distid:someid 631 632Verify some data using an L<SM2(7)> certificate and a specific ID: 633 634 openssl pkeyutl -verify -certin -in file -inkey sm2.cert -sigfile sig \ 635 -rawin -digest sm3 -pkeyopt distid:someid 636 637Decrypt some data using a private key with OAEP padding using SHA256: 638 639 openssl pkeyutl -decrypt -in file -inkey key.pem -out secret \ 640 -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256 641 642Create an ML-DSA key pair and sign data with a specific context string: 643 644 $ openssl genpkey -algorithm ML-DSA-65 -out mldsa65.pem 645 $ openssl pkeyutl -sign -in file.txt -inkey mldsa65.pem -out sig -pkeyopt context-string:example 646 647Verify a signature using ML-DSA with the same context string: 648 649 $ openssl pkeyutl -verify -in file.txt -inkey mldsa65.pem -sigfile sig -pkeyopt context-string:example 650 651Generate an ML-KEM key pair and use it for encapsulation: 652 653 $ openssl genpkey -algorithm ML-KEM-768 -out mlkem768.pem 654 $ openssl pkey -in mlkem768.pem -pubout -out mlkem768_pub.pem 655 $ openssl pkeyutl -encap -inkey mlkem768_pub.pem -pubin -out ciphertext -secret shared_secret.bin 656 657Decapsulate a shared secret using an ML-KEM private key: 658 659 $ openssl pkeyutl -decap -inkey mlkem768.pem -in ciphertext -secret decapsulated_secret.bin 660 661Create an SLH-DSA key pair and sign data: 662 663 $ openssl genpkey -algorithm SLH-DSA-SHA2-128s -out slh-dsa.pem 664 $ openssl pkeyutl -sign -in file.txt -inkey slh-dsa.pem -out sig 665 666Verify a signature using SLH-DSA: 667 668 $ openssl pkeyutl -verify -in file.txt -inkey slh-dsa.pem -sigfile sig 669 670=head1 SEE ALSO 671 672L<openssl(1)>, 673L<openssl-genpkey(1)>, 674L<openssl-pkey(1)>, 675L<openssl-rsautl(1)> 676L<openssl-dgst(1)>, 677L<openssl-rsa(1)>, 678L<openssl-genrsa(1)>, 679L<openssl-kdf(1)> 680L<EVP_PKEY_CTX_set_hkdf_md(3)>, 681L<EVP_PKEY_CTX_set_tls1_prf_md(3)>, 682 683=head1 HISTORY 684 685Since OpenSSL 3.5, 686the B<-digest> option implies B<-rawin>, and these two options are 687no longer required when signing or verifying with an Ed25519 or Ed448 key. 688 689Also since OpenSSL 3.5, the B<-kemop> option is no longer required for any of 690the supported algorithms, the only supported B<mode> is now the default. 691 692The B<-engine> option was deprecated in OpenSSL 3.0. 693 694=head1 COPYRIGHT 695 696Copyright 2006-2025 The OpenSSL Project Authors. All Rights Reserved. 697 698Licensed under the Apache License 2.0 (the "License"). You may not use 699this file except in compliance with the License. You can obtain a copy 700in the file LICENSE in the source distribution or at 701L<https://www.openssl.org/source/license.html>. 702 703=cut 704