fork(2) download
  1. require "openssl"
  2. require "base64"
  3. require "time"
  4. require "json"
  5.  
  6. class YHSDMultipass
  7.  
  8. attr_accessor :cipher_key
  9. attr_accessor :cipher_iv
  10.  
  11. def initialize(key)
  12. @cipher_key = key[0, 16]
  13. @cipher_iv = key[16, 16]
  14. end
  15.  
  16. def aes_encrypt(data)
  17. cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
  18. cipher.encrypt
  19. cipher.key = @cipher_key
  20. cipher.iv = @cipher_iv
  21. ciphertext = cipher.update(data) + cipher.final
  22. ciphertext.to_s
  23. end
  24.  
  25. end
  26.  
  27. # 用户信息JSON
  28. customer_data = {
  29. "uid" => "test@youhaosuda.com",
  30. "type" => "email",
  31. "name" => "test"
  32. }
  33. # 接入密钥
  34. secret_key = '095AE461E2554EED8D12F19F9662247E'
  35. # 店铺主域名
  36. shop_domain = 'youhaosuda.com'
  37.  
  38. encrypt_data = YHSDMultipass.new(secret_key).aes_encrypt(customer_data.to_json)
  39. redirect_url = "http://" + shop_domain + "/account/multipass/login/#{encrypt_data}"
  40.  
  41. puts "customer_data:" + customer_data.to_json
  42. puts "encrypt_data:" + encrypt_data
  43. puts "redirect_url:" + redirect_url
Success #stdin #stdout 0.04s 11448KB
stdin
Standard input is empty
stdout
customer_data:{"uid":"test@youhaosuda.com","type":"email","name":"test"}
encrypt_data:����k����[q�m��s��k�}���
3�y&3�M�ζhBf�qq ���\�kr�7
redirect_url:http://y...content-available-to-author-only...a.com/account/multipass/login/����k����[q�m��s��k�}���
3�y&3�M�ζhBf�qq ���\�kr�7