Last active
May 9, 2023 17:48
-
-
Save jeffdonthemic/4706139076dc368ce27c5709c2e6787a to your computer and use it in GitHub Desktop.
Ruby crypto sign/verify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
require 'base64' | |
private_key = File.read("./salesforce_private.key") | |
public_key = File.read("./salesforce_public.key") | |
data = "reports50" | |
priv_key = OpenSSL::PKey::RSA.new(private_key) | |
signature = priv_key.sign_pss("RSA-SHA512", data, salt_length: :digest, mgf1_hash: "RSA-SHA512") | |
puts Base64.strict_encode64(signature) | |
# pub_key = priv_key.public_key | |
# puts pub_key.verify_pss("RSA-SHA512", signature, data, salt_length: :auto, mgf1_hash: "RSA-SHA512") # => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here are the docs: https://ruby-doc.org/stdlib-3.1.0/libdoc/openssl/rdoc/OpenSSL/PKey/RSA.html#method-i-sign_pss