Method: ExtID::Type#decode
- Defined in:
- lib/extid.rb
#decode(s) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/extid.rb', line 35 def decode(s) raise ArgumentError, "invalid prefix" unless s.start_with?(@prefix) hex_ciphertext = s[@prefix.size..] ciphertext = [hex_ciphertext].pack("H*") cipher = OpenSSL::Cipher.new('AES-128-ECB') cipher.decrypt cipher.key = @key cipher.padding = 0 plaintext = cipher.update(ciphertext) + cipher.final plaintext[0, 8].unpack("q>").first end |