Class: AlipayGlobal::Sign::RSA
- Inherits:
-
Object
- Object
- AlipayGlobal::Sign::RSA
- Defined in:
- lib/alipay_global/sign/rsa.rb
Class Method Summary collapse
- .private_key ⇒ Object
- .sign(string, supplied_private_key = nil) ⇒ Object
- .verify?(string, public_key, sign) ⇒ Boolean
Class Method Details
.private_key ⇒ Object
7 8 9 10 |
# File 'lib/alipay_global/sign/rsa.rb', line 7 def self.private_key raise ArgumentError, "Assign valid location for RSA private key location :: #AlipayGlobal.private_key_location = #{AlipayGlobal.private_key_location}" if !AlipayGlobal.private_key_location File.read(AlipayGlobal.private_key_location) end |
.sign(string, supplied_private_key = nil) ⇒ Object
12 13 14 15 16 |
# File 'lib/alipay_global/sign/rsa.rb', line 12 def self.sign(string, supplied_private_key = nil) key = supplied_private_key || private_key rsa = OpenSSL::PKey::RSA.new(key) Base64.encode64(rsa.sign(OpenSSL::Digest::SHA256.new, string)) end |
.verify?(string, public_key, sign) ⇒ Boolean
18 19 20 21 |
# File 'lib/alipay_global/sign/rsa.rb', line 18 def self.verify?(string, public_key, sign) rsa = OpenSSL::PKey::RSA.new(public_key) rsa.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(sign), string) end |