app/models/unidom/common/concerns/sha512_digester.rb in unidom-common-1.10 vs app/models/unidom/common/concerns/sha512_digester.rb in unidom-common-1.11

- old
+ new

@@ -37,13 +37,33 @@ end module ClassMethods + ## + # 对明文 message 进行 SHA-512 摘要, pepper 是用于增加混乱的内容。如: + # class SomeModel + # include Unidom::Common::Concerns::Sha512Digester + # def self.some_method(param_1) + # digest param_1 + # # 或者 + # digest param_1, pepper: 'my_pepper' + # end + # end def digest(message, pepper: nil) message.present? ? Digest::SHA512.digest("#{message}_#{Rails.application.secrets[:secret_key_base]}_#{pepper}") : nil end + ## + # 对明文 message 进行 SHA-512 摘要,并以16进制的形式返回, pepper 是用于增加混乱的内容。如: + # class SomeModel + # include Unidom::Common::Concerns::Sha512Digester + # def self.some_method(param_1) + # hex_digest param_1 + # # 或者 + # hex_digest param_1, pepper: 'my_pepper' + # end + # end def hex_digest(message, pepper: nil) message.present? ? Unidom::Common::Numeration.hex(digest(message, pepper: pepper)) : nil end end