API에서 가져와 일부 오류가 발생하는 일부 데이터의 암호를 해독하려고합니다.Blowfish를 사용하여 데이터를 해독하려고 할 때 NoMethodError가 발생했습니다.
일부 배경
내가 복어를 사용하여 암호화 한 후 base64로 문자열 인코딩 및 JSON 문자열에서 이용할 수있게했다 가져 오는거야 데이터입니다. 여기에 JSON 문자열이 내가 뭘 내 루비 스크립트에서
{"payload":"BR0UzF38W4oVB7fjP6WgClqdaMKIYTl661mpneqoXQYIYkBQvjlMQZ+yn...."}
모습의 샘플입니다 다음
require 'crypt/blowfish'
require 'base64'
# get json data
response = Net::HTTP.get(URI('http://www.url-to-json.com'))
results = JSON.parse(response)
# decode the base64 results
decoded = Base64.decode64(results['payload'])
# setup blowfish object with key
blowfish = Crypt::Blowfish.new('my_secret_key')
# decrypt the data
puts blowfish.decrypt_string(decoded)
그리고이 반환되는 오류입니다 :
/Users/Ken/.rvm/gems/[email protected]/gems/crypt-2.2.1/lib/crypt/stringxor.rb:4:in `^': undefined method `b' for "java.uti":String (NoMethodError)
from /Users/Ken/.rvm/gems/[email protected]/gems/crypt-2.2.1/lib/crypt/cbc.rb:62:in `decrypt_stream'
from /Users/Ken/.rvm/gems/[email protected]/gems/crypt-2.2.1/lib/crypt/cbc.rb:115:in `decrypt_string'
from /Users/Ken/Code/vs/scripts/test.rb:55:in `run'
from init.rb:43:in `<main>'
을
오류의 원인을 파악할 수 있습니까? 나는 몇 시간 동안 그것을 디버깅 해왔고 어떤 진전을 이룰 수없는 것처럼 보였다. 내 생각 엔 인코딩 문제이지만 인코딩을 강제로 사용하면 force_encoding()
같은 오류가 발생합니다.
그리고이 앱에 Ruby 버전 1.9.3-p327에 잠겨 있습니다.
미리 도움을 청하십시오!
저에게는 crypt gem의 버그처럼 보이지만 확인할 수는 없습니다. 손으로 만든 데이터를 제공 할 때 작동합니까? – Felix