require "base64"
require "openssl"
class DecodeWechatEncrypted
attr_accessor :appId, :sessionKey
def initialize appId, sessionKey
self.appId = appId
self.sessionKey = sessionKey
end
def decryptData encryptedData, iv
sessionKey = Base64.decode64(self.sessionKey)
encryptedData = Base64.decode64(encryptedData)
iv = Base64.decode64(iv)
cipher = OpenSSL::Cipher::Cipher.new("AES-128-ECB")
cipher.decrypt
cipher.key = sessionKey
cipher.iv = iv
cipher.update(encryptedData) + cipher.final
end
end
其中
cipher.iv = iv
这一行,报了一个
iv=': iv must be 0 bytes (ArgumentError)
这个我就不太懂了,有人写过这个吗