Class: Kount::Khash
- Inherits:
-
Object
- Object
- Kount::Khash
- Defined in:
- lib/kount/utils/khash.rb
Class Method Summary collapse
- .getkhash(data, len, m) ⇒ Object
- .hash_check_payment(plain_text, ksalt) ⇒ Object
- .hash_gift_card(plain_text, ksalt, merchant_id) ⇒ Object
- .hash_payment_token(plain_text, ksalt) ⇒ Object
-
.hash_token(plain_text, ptyp, ksalt, merchant_id = '') ⇒ String
KHASH version of string.
-
.khashed?(val) ⇒ Boolean
True if token is already khashed.
Class Method Details
.getkhash(data, len, m) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kount/utils/khash.rb', line 16 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
37 38 39 40 41 42 |
# File 'lib/kount/utils/khash.rb', line 37 def self.hash_check_payment(plain_text, ksalt) return plain_text if khashed?(plain_text) first_six = plain_text[0..5] mashed = getkhash(plain_text, 14, ksalt) "#{first_six}#{mashed}" end |
.hash_gift_card(plain_text, ksalt, merchant_id) ⇒ Object
44 45 46 47 |
# File 'lib/kount/utils/khash.rb', line 44 def self.hash_gift_card(plain_text, ksalt, merchant_id) mashed = getkhash(plain_text, 14, ksalt) "#{merchant_id}#{mashed}" end |
.hash_payment_token(plain_text, ksalt) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/kount/utils/khash.rb', line 30 def self.hash_payment_token(plain_text, ksalt) return plain_text if khashed?(plain_text) first_six = plain_text[0..5] mashed = getkhash(plain_text, 14, ksalt) "#{first_six}#{mashed}" end |
.hash_token(plain_text, ptyp, ksalt, merchant_id = '') ⇒ String
Returns KHASH version of string.
6 7 8 9 10 11 12 13 14 |
# File 'lib/kount/utils/khash.rb', line 6 def self.hash_token(plain_text, ptyp, ksalt, merchant_id = '') if ptyp == 'CARD' HashPaymentToken(plain_text, ksalt) elsif ptyp == 'CHEK' HashCheckPayment(plain_text, ksalt) else HashGiftCard(plain_text, ksalt, merchant_id) end end |
.khashed?(val) ⇒ Boolean
Returns True if token is already khashed.
51 52 53 |
# File 'lib/kount/utils/khash.rb', line 51 def self.khashed?(val) true if val =~ /(\d{6}[A-Z0-9]{14})/ end |