Signatures

The following Ruby signature examples use the OpenSSL cryptography toolkit.

Sign data

Signing data using RSA private key with PKCS1 v1.5 padding and SHA256 hash:

require 'openssl'
    def sign_data(key, data)
    key.sign(OpenSSL::Digest::SHA256.new, data)
end

Verify signature

Decrypt a package using RSA private key with PKCS1-OAEP padding:

require 'openssl'
def verify_sign(key, signature, data)
    # Verifies with a public key that the data was signed with their private key
    pubkey = key.public_key
    if pubkey.verify(OpenSSL::Digest::SHA256.new, signature, data)
        puts 'the signature is valid'
    else
        puts 'the signature is invalid'
    end
end

User Contributed

LaunchKey links to user contributed code as a resource to its community. LaunchKey does not in any way guarantee or warrant the quality and security of these code bases. User contributed code is supported by the creators. If you do find a link from the site to user contributed code that is malicious or inappropriate in any way, please report that link to LaunchKey immediately and we will investigate the claim. Submit any issue to LaunchKey support at https://launchkey.com./support. ×