6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/postfinancecheckout-ruby-sdk/encryption_util.rb', line 6
def self.is_content_valid(content, signature, public_key, encryption_algorithm)
algorithm_class = get_algorithm_class(encryption_algorithm)
raise "Unsupported algorithm: #{encryption_algorithm}" if algorithm_class.nil?
begin
signature = Base64.decode64(signature)
rescue ArgumentError
raise 'Invalid signature value format'
end
begin
public_key_bytes = Base64.decode64(public_key)
rescue ArgumentError
raise 'Invalid public key value format'
end
public_key = OpenSSL::PKey.read(public_key_bytes)
begin
return public_key.verify(OpenSSL::Digest::SHA256.new, signature, content)
rescue OpenSSL::PKey::PKeyError, OpenSSL::PKey::ECError, OpenSSL::PKey::EC::Point::Error
return false
end
end
|