Class: ReCaptcha::MHClient
- Inherits:
-
Object
- Object
- ReCaptcha::MHClient
- Defined in:
- lib/recaptcha.rb
Instance Method Summary collapse
- #encrypt(string) ⇒ Object
-
#initialize(pubkey, privkey) ⇒ MHClient
constructor
A new instance of MHClient.
- #pad(str) ⇒ Object
Constructor Details
#initialize(pubkey, privkey) ⇒ MHClient
56 57 58 59 60 |
# File 'lib/recaptcha.rb', line 56 def initialize(pubkey, privkey) @pubkey=pubkey @privkey=privkey @host='mailhide.recaptcha.net' end |
Instance Method Details
#encrypt(string) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/recaptcha.rb', line 61 def encrypt(string) padded = pad(string) iv="\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00" cipher=OpenSSL::Cipher::Cipher.new("AES-128-CBC") binkey = @privkey.unpack('a2'*16).map{|x| x.hex}.pack('c'*16) cipher.encrypt cipher.key=binkey cipher.iv=iv ciphertext = [] cipher.padding=0 ciphertext = cipher.update(padded) ciphertext << cipher.final() rescue nil Base64.encode64(ciphertext).strip.gsub(/\+/, '-').gsub(/\//, '_').gsub(/\n/,'') end |
#pad(str) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/recaptcha.rb', line 75 def pad(str) l= 16-(str.length%16) l.times do str<< l end str end |