rsa_pss_sign.sh 744 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. SIGOPT=rsa_padding_mode:pss
  3. SIGOPT2=rsa_pss_saltlen:-1
  4. function usage() {
  5. cat <<_EOT_
  6. Usage:
  7. $0 <pri key> <pub key> <file name>
  8. pri key : private key for sign/verify
  9. pub key : public key for sign/verify
  10. file name : file name to be signed
  11. _EOT_
  12. exit 1
  13. }
  14. if [ $# -ne 3 ]; then
  15. usage
  16. fi
  17. # $1 private key for sign/verify
  18. # $2 public key for verify
  19. # $3 file for sign/verify
  20. openssl dgst -sha256 -sign $1 -sigopt $SIGOPT -sigopt $SIGOPT2 -out $3.sign $3
  21. echo verify by private key
  22. openssl dgst -sha256 -prverify $1 -sigopt $SIGOPT -sigopt $SIGOPT2 -signature $3.sign $3
  23. echo verify by public key
  24. openssl dgst -sha256 -verify $2 -sigopt $SIGOPT -sigopt $SIGOPT2 -signature $3.sign $3