Module: Kount::Khash
- Defined in:
- lib/kount/utils/khash.rb
Class Method Summary collapse
-
.getkhash(data, len, m) ⇒ String
Compute a base64 hash of the provided data.
-
.hash_check_payment(plain_text, ksalt) ⇒ Object
DEPRECATED: Use Kount::Khash.hash_payment_token instead.
-
.hash_gift_card(plain_text, ksalt, merchant_id) ⇒ String
Hash a gift card number.
-
.hash_payment_token(plain_text, ksalt) ⇒ String
Hash a PAN.
-
.khashed?(val) ⇒ Boolean
True if token is already khashed.
Class Method Details
.getkhash(data, len, m) ⇒ String
Compute a base64 hash of the provided data.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/kount/utils/khash.rb', line 56 def self.getkhash(data, len, m) a = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' r = Digest::SHA1.hexdigest("#{data}.#{m}") c = '' len = 17 if len > 17 limit = 2 * len i = 0 while i < limit c << a[r[i..i + 6].to_i(16) % 36] i += 2 end c end |
.hash_check_payment(plain_text, ksalt) ⇒ Object
DEPRECATED: Use Kount::Khash.hash_payment_token instead.
23 24 25 26 |
# File 'lib/kount/utils/khash.rb', line 23 def self.hash_check_payment(plain_text, ksalt) warn "[DEPRECATION] use Kount::Khash.hash_payment_token instead" hash_payment_token(plain_text, ksalt) end |
.hash_gift_card(plain_text, ksalt, merchant_id) ⇒ String
Hash a gift card number.
Use the six characters of the merchant id so that hashed cards can be unique across the entire domain.
Example usage:
hashed = Kount::SecurityMash.hash_gift_card("3245876", salt, "123456")
Expect: 1234569HXH32Y5NNJCGB
43 44 45 46 47 |
# File 'lib/kount/utils/khash.rb', line 43 def self.hash_gift_card(plain_text, ksalt, merchant_id) return plain_text if khashed?(plain_text) mashed = getkhash(plain_text, 14, ksalt) "#{merchant_id}#{mashed}" end |
.hash_payment_token(plain_text, ksalt) ⇒ String
Hash a PAN.
Preserves first six characters of the input so that hashed cards can be categorized by Bank Identification Number (BIN).
Example usage:
hashed = Kount::Khash.hash_payment_token("4111111111111111", ksalt)
Expect: 411111WMS5YA6FUZA1KC
16 17 18 19 20 |
# File 'lib/kount/utils/khash.rb', line 16 def self.hash_payment_token(plain_text, ksalt) return plain_text if khashed?(plain_text) mashed = getkhash(plain_text, 14, ksalt) "#{plain_text[0..5]}#{mashed}" end |
.khashed?(val) ⇒ Boolean
Returns True if token is already khashed.
72 73 74 |
# File 'lib/kount/utils/khash.rb', line 72 def self.khashed?(val) true if val =~ /(\d{6}[A-Z0-9]{14})/ end |