Class: Moxml::Signature::Algorithms::RsaPkcs1Sha

Inherits:
SignatureMethodBase show all
Defined in:
lib/moxml/signature/algorithms/rsa_pkcs1_sha.rb

Overview

RSASSA-PKCS1-v1_5 per RFC 3447 ยง8.2, bound to a digest.

One Ruby class registered under five URIs (sha1 / sha224 / sha256 / sha384 / sha512). When instantiated, the class is told which URI was resolved so it can pick the right digest.

Constant Summary collapse

PAIRINGS =
{
  "http://www.w3.org/2000/09/xmldsig#rsa-sha1" => "SHA1",
  "http://www.w3.org/2001/04/xmldsig-more#rsa-sha224" => "SHA224",
  "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" => "SHA256",
  "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384" => "SHA384",
  "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512" => "SHA512",
}.freeze

Instance Method Summary collapse

Methods inherited from SignatureMethodBase

identifier, #sign, #verify

Constructor Details

#initialize(identifier_uri:, parameters: nil) ⇒ RsaPkcs1Sha

Returns a new instance of RsaPkcs1Sha.



24
25
26
27
28
# File 'lib/moxml/signature/algorithms/rsa_pkcs1_sha.rb', line 24

def initialize(identifier_uri:, parameters: nil)
  super(nil)
  @identifier_uri = identifier_uri
  @parameters = parameters
end

Instance Method Details

#compute_signature(data, key) ⇒ Object



30
31
32
33
# File 'lib/moxml/signature/algorithms/rsa_pkcs1_sha.rb', line 30

def compute_signature(data, key)
  rsa_key = coerce_key(key)
  rsa_key.sign(digest_name, data)
end

#verify_signature(data, key, signature) ⇒ Object



35
36
37
38
# File 'lib/moxml/signature/algorithms/rsa_pkcs1_sha.rb', line 35

def verify_signature(data, key, signature)
  rsa_key = coerce_key(key)
  rsa_key.verify(digest_name, signature, data)
end